mickeymouse Posted January 17, 2019 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted January 17, 2019 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. Link to comment Share on other sites More sharing options...
mickeymouse Posted January 17, 2019 Author Share Posted January 17, 2019 1) Shouldn't the traditional way still work. 2) Don't know how to do the modern way. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 17, 2019 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 17, 2019 Share Posted January 17, 2019 I'll move this to Javascript since it doesn't have anything to do with PHP. Link to comment Share on other sites More sharing options...
mickeymouse Posted January 17, 2019 Author 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 18, 2019 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now