mickeymouse 0 Posted January 17, 2019 Report Share Posted January 17, 2019 Shouldn't this code return me to my from and not take action to open the next program/file. function formcheck(myform) {alert('Form Check.'); return false;} with the following form parameters: <form name='AmendForm' action='FT_AmendUpdate.php' method='POST' onsubmit='return formcheck(AmendForm)'> Whether I use return true or return false, the submit displays the "Form Check" message and then opens the next program/file: FT_AmendUpdate.php Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 17, 2019 Report Share Posted January 17, 2019 The modern way to do that is to get the event object inside the event handler, and cancel the default action. Quote Link to post Share on other sites
mickeymouse 0 Posted January 17, 2019 Author Report Share Posted January 17, 2019 1) Shouldn't the traditional way still work. 2) Don't know how to do the modern way. Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 17, 2019 Report Share Posted January 17, 2019 Shouldn't the traditional way still work. Depends on what the browser vendors decide to do. I don't believe that method is part of the standard, so when you're talking about non-standard things you'll find that they work differently in different browsers. That will work in older browsers, sure. It might not work on mobile devices though, for example. https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault Note that those examples also attach the listener using addEventListener rather than using event attributes. Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 17, 2019 Report Share Posted January 17, 2019 I'll move this to Javascript since it doesn't have anything to do with PHP. Quote Link to post Share on other sites
mickeymouse 0 Posted January 17, 2019 Author Report Share Posted January 17, 2019 It works perfectly on my other forms so it's not a browser related problem. I'll look at the link you gave me in more detail later but right now I would prefer to find the problem and fix it rather than venture into new stuff at this time. As I said, it works in my other forms so I don't see why it shouldn't work in this one. Thanks for your help and thanks for moving the item to Javascript - I keep thinking these functions I've coded are PHP - sorry about that. Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 18, 2019 Report Share Posted January 18, 2019 Sounds like you've got an error stopping the other code from running. Make sure to check the console in your browser's developer tools. It might be the variable AmendForm, it doesn't look like it's defined. Pass this instead to pass the element where you have the attribute. Quote Link to post Share on other sites
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.