0

I'm trying to call a PHP funtion after onclick event, the function needs a DOM element's value as parameter (this is why i have to use jquery as well)

I want to have something which looks like this :

<button type="button" onclick="document.write('<?php hello("parameter") ?>');">Submit</button>

Here's what i've been able to do so far, but it's not working :

<button type="button" onclick="document.write('<?php hello("<script>$(#idproduct).text()</script>") ?>');">Submit</button>

Any help would be appreciated, thank's.

4
  • 3
    impossible. php runs on the server. that php code will execute ONCE when the page is generated, and get replaced with its output. it will never reach the client's browser. and even if it did reach the browser, it is incredibly unlikely that the user's browser could execute PHP in the first place. Commented Mar 23, 2016 at 21:33
  • It is indeed not possible - PHP runs on the server, Javascript in the client's browser. You need to look up sending the data to the backend server via AJAX - there's a hundred ways to do this, like stackoverflow.com/questions/2269307/… Commented Mar 23, 2016 at 21:50
  • You will have to use ajax and send a post/get request Commented Mar 23, 2016 at 21:51
  • Thank you guys, i wanted to avoid the AJAX method and thought there could be an easier way to do it .. but it seems there is no alternative. Commented Mar 23, 2016 at 21:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.