Welcome Guest, Not a member yet? Register   Sign In
Onclick does nothing
#6

(This post was last modified: 05-13-2019, 03:34 PM by albertleao.)

(05-13-2019, 10:58 AM)Deborah Wrote: Useful thanks, understand more now about server(php)/client(js).  I tried below, which adds a row when the page loads, but not with onclick.  Dunno how to use js to send a request to php, which should be simple even for novice.

<script>
function add_row() {
<?php $this->table_model->add_row( 'file.doc' ); ?>
}
</script>

<a href="http://downloadfiles.com/file.doc" onclick="add_row()">

This is still wrong.

Anything in a <?php ?> tag will only run on your server. Anything inside your <script></script> tag will run on your client. Before diving into this anymore, I'd recommend reading up and learning about server side languages and client side languages.

The reason it's adding the row when the page loads is because the server is executing that code when rendering the page and not the client. You're looking for that functionality to occur when someone clicks the <a></a> tag, which is client side logic. You are getting them both confused.

Your javascript function needs to make an http xhr call to your backend service. This is called ajax. If you are calling <?php $this... ?> in your html, you are doing it wrong.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply


Messages In This Thread
Onclick does nothing - by Deborah - 05-13-2019, 09:17 AM
RE: Onclick does nothing - by ciadmin - 05-13-2019, 09:41 AM
RE: Onclick does nothing - by albertleao - 05-13-2019, 09:58 AM
RE: Onclick does nothing - by Deborah - 05-13-2019, 10:58 AM
RE: Onclick does nothing - by donpwinston - 05-13-2019, 03:25 PM
RE: Onclick does nothing - by albertleao - 05-13-2019, 03:33 PM
RE: Onclick does nothing - by Wouter60 - 05-13-2019, 11:10 PM
RE: Onclick does nothing - by albertleao - 05-14-2019, 10:52 AM
RE: Onclick does nothing - by Deborah - 05-16-2019, 10:31 AM
RE: Onclick does nothing - by albertleao - 05-16-2019, 12:02 PM
RE: Onclick does nothing - by Deborah - 05-16-2019, 01:28 PM
RE: Onclick does nothing - by albertleao - 05-17-2019, 07:01 AM
RE: Onclick does nothing - by Deborah - 05-17-2019, 07:20 AM
RE: Onclick does nothing - by shivambhatele - 06-23-2019, 09:43 PM
RE: Onclick does nothing - by MattZand - 09-17-2019, 02:44 PM
RE: Onclick does nothing - by InsiteFX - 07-04-2021, 02:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB