How do I add php to button onclick? I dont wish to use jquery as i have been using javascript and i dont wanna complicate things and jqeury is all i could generally find. does it basically work the same way as in javascript, you make a function using php then call the function using inclick ? e.g. <?php function Myfunction() { } ?> <input type = "button" name="click here" onClick="return Myfunction()";> sorry for my n00b question haha
I could think of a pattern: <input type="button" name="click here" onclick="location.href=myfunctions.php?run=Myfunction";> HTML: with your myfunctions.php containing: if($_GET['run'] === 'Myfunction'){ Myfunction(); } PHP: But what does Myfunction() do anyway?
PHP is run server-side, not client-side. You can't call PHP directly from a event. Doesn't work that way. @hdewantara's example would load the result as a new page, but at that point why not use an ANCHOR? I don't think that's even close to what @DevDream is actually asking. To use the result of an onclick for SOMETHING scripted (damned if we know what) that's PHP/server-side, you'd have to use some form of AJAX type scripting to call it. Though @hdewantara asked a damned important question, what is that function supposed to do, and why would you be calling a server-side function from client-side code?
just echo "thanks for submitting the form, then use the post method to post the value of the button whose name is firstname. like echo "Thanks $_post("firstname"); ???
would you mind posting the code that could do this for a button called submit where there is a input type text which name is firstName. thanks!
There must be a million tutorials on how to submit a form using ajax/JavaScript. And yes, you can do it with plain JavaScript
Php runs on the server, you need JavaScript to send the info to the server. Work through some tutorials and you'll get a better understanding.
Actually, you do NOT need JavaScript to send it to the server, unless you WANT to piss off users. What you're looking for is NOT a <button> tag with some scripttardery, it's <input type="submit"> with a proper full page load. Which even IF you were to enhance that with JavaScript to avoid the page-load, it's generally a good idea to implement WITHOUT the scripted asshattery FIRST for the people who actively block or have scripting unavailable! Sounds like you're just building a <form>, so USE THE FORM PROPERLY FIRST! THEN if you want to enhance it with scripting do so. I have this mantra about JavaScript: If you can't make a fully functional page without JavaScript FIRST, you likely have no business adding scripting to it! Something like a login? Scripting just adds another layer of complexity to be hacked -- see my other mantra: The less code you use, the less there is to break.