stockton Posted May 7, 2009 Share Posted May 7, 2009 I have the following code in a html page and I need to know how to code the line starting <a href="events.php"....... to get it to work rather than call the onclick="submit_click() on the line above. The submit_click is obviously a JavaScript function that I do not want to run when the Back button is clicked. <input type=button value="Update" onclick="submit_click()"> <a href="events.php?EventID=0"><BUTTON TYPE="submit">Back</BUTTON></a> Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Why can't you just remove the onclick="submit_click()" part? if you're changing it to a link, it'll have the same result. Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-828501 Share on other sites More sharing options...
stockton Posted May 7, 2009 Author Share Posted May 7, 2009 Please tell me more. How would you code it to still call submit_click at the appropriate time ie when the Update button is clicked? Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-828547 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Well it does that already as you can see. The back button wouldn't trigger the JavaScript again. Does your PHP page redirect the user after it finishes its task? If so, then the back button goes back to the PHP page so it seems like the UPDATE button got ran again when really it didn't. An onclick function doesn't execute itself. Can you explain more about the issue if the above-mentioned is not the case? Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-828556 Share on other sites More sharing options...
stockton Posted May 8, 2009 Author Share Posted May 8, 2009 Yesterday I watched a user click the Back button only to end up getting the database updated. Just as if they had clicked the Update button. I checked the database before the click of the Back button & after and the record had been altered. Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-829277 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Does your functionality work something like this - 1. Click update button. 2. Sends to some PHP file to update database. 3. Redirect the user. ? Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-829459 Share on other sites More sharing options...
stockton Posted May 8, 2009 Author Share Posted May 8, 2009 Yes it does. On on the other hand clicking the Back button should take them straight back to where they came from, the menu. Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-829471 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 No, it would take them back to the PHP page. o.O Example - 1. I'm on index.php and I click submit. 2. The form redirect me to process.php that inserts data to the DB. 3. process.php then redirects me back to index.php If I press the back button after #3, I go back to #2, which runs the script again! Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-829504 Share on other sites More sharing options...
stockton Posted May 8, 2009 Author Share Posted May 8, 2009 It is not a matter of clicking Update & then clicking Back. User either clicks Back or Update. Quote Link to comment https://forums.phpfreaks.com/topic/157228-script-called-when-it-is-not-needed/#findComment-829553 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.