add a code to button on click/submit
-
Hi all i would like to write an on click/submit event on a button and im doing it like this <form name="form1" action="" method="post"> <input type="button" name="mybutton" onclick="<?php print "my Test"; ?>"; form1.submit()"> </form> i know onclick is a javascript function,does anyone know what's the equivalent in PHP. Regards
-
Hi all i would like to write an on click/submit event on a button and im doing it like this <form name="form1" action="" method="post"> <input type="button" name="mybutton" onclick="<?php print "my Test"; ?>"; form1.submit()"> </form> i know onclick is a javascript function,does anyone know what's the equivalent in PHP. Regards
JavaScript runs at the client side, where the button is. PHP runs at the server, and is unaware of someone clicking a button at the client side. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Hi all i would like to write an on click/submit event on a button and im doing it like this <form name="form1" action="" method="post"> <input type="button" name="mybutton" onclick="<?php print "my Test"; ?>"; form1.submit()"> </form> i know onclick is a javascript function,does anyone know what's the equivalent in PHP. Regards
<?php if($_POST['submit']){ echo "form submitted"; } ?> <div id="mydiv">This is a div contents</div> <form name="form1" action="" method="post"> <input type="button" name="mybutton" id="mybutton" onclick="document.getElementById('mydiv').innerHTML = 'my Test'" value="fill div" /> <input type="submit" value="submit" name="submit" /> </form> The above code shows the difference between javascript & php. Javascript works on the page on the client side ("fill div" btn does not refresh the page). When you "submit" the form the contents of it are sent to the server. There the server sees that a form has been submitted and formats the page as required ( here it writes "form submitted to the beginning of the body text before sending it back to the client).
-
JavaScript runs at the client side, where the button is. PHP runs at the server, and is unaware of someone clicking a button at the client side. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
Right, basically there is no equivalent. PHP runs before the client sees the web page and only on the server. Javascript/VB run on the client side (browser) after the page has been processed by the PHP. That is why it is called PHP Hypertext Pre-processor.