lljr Posted August 16, 2009 Share Posted August 16, 2009 I cant seem to find a code to execute a PHP section when a button is pressed, can anybody supply this or have a link? thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/170546-button-to-execute/ Share on other sites More sharing options...
peter_anderson Posted August 16, 2009 Share Posted August 16, 2009 What do you mean? Like a submit button? Quote Link to comment https://forums.phpfreaks.com/topic/170546-button-to-execute/#findComment-899607 Share on other sites More sharing options...
lljr Posted August 16, 2009 Author Share Posted August 16, 2009 no, i want to use the random coding to insert a random number but only when a button is pushed, but i dont know how to do the button part... Quote Link to comment https://forums.phpfreaks.com/topic/170546-button-to-execute/#findComment-899608 Share on other sites More sharing options...
oni-kun Posted August 16, 2009 Share Posted August 16, 2009 A button is clientside, PHP is a serverside language. You'd need to use a form like this.. <form action="whatever.php" method="post"> <input type="button" value="click me to calculate!"/> </form And it'll POST and inputs etc. to whatever.php. If you use a text input for example like you'd see in normal forms.. if an input was named 'name="ID" ' you could see it in PHP as.. $_POST['ID'].. Edit: You may want to use JS to insert a random number into the box. You can do buttons like this.. <button onClick="document.getelementbyID('rand1').value = 4">Button</button> Quote Link to comment https://forums.phpfreaks.com/topic/170546-button-to-execute/#findComment-899610 Share on other sites More sharing options...
Andy-H Posted August 16, 2009 Share Posted August 16, 2009 You mean like <input type="image" name="submit" > ??? When an image is clicked it sends the XY coordinates of the screen position that the mouse clicked. To execute code with an image input you have to use if ( isSet($_POST['submit_x']) ) { //code } //or if ( isSet($_POST['submit_y']) ) { //code } Quote Link to comment https://forums.phpfreaks.com/topic/170546-button-to-execute/#findComment-899612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.