Jump to content
mickeymouse

return from function???

Recommended Posts

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

Share this post


Link to post
Share on other sites

The modern way to do that is to get the event object inside the event handler, and cancel the default action.

Share this post


Link to post
Share on other sites

1) Shouldn't the traditional way still work.

2) Don't know how to do the modern way.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I'll move this to Javascript since it doesn't have anything to do with PHP.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...