Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EventListener

Status
Not open for further replies.

RicksAtWork

Programmer
Nov 1, 2005
120
GB
I have a method called IsValidForUpdate

It has an alert and also returns false.

I have set up an event listener to check for the 'submit' event of a submit button. When these are fired IsValidForUpdate is called.

In explorer:
When I click on the button, the alert pops up and the form doesnt submit!

Result.

In firefox:
When I click on the button, the alert pops up and the form still submits!

Why?!?!?!





 
Submit buttons do not have a submit event - maybe this is the problem?

Forms has submit events, submit buttons have onclick events. You should use the former to detect form submissions.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Tried attaching to the submit event of the form and the click event of the button.

In both cases the method called doesnt seem to stop submission of the form even though it returns false!!!

This is a real spanner in the works!!!

Any ideas?
 
Now you've discovered a different problem - if you call the submit event programatically, the onsubmit handler is bypassed. Do not add an onclick event to the submit button - just let it do it's job.

All you need to do is have a standard submit button, with no onclick event:

Code:
<input type="submit" value="Your text here" />

and then around that, a form with an onsubmit handler, which returns true or false:

Code:
<form ... onsubmit="return(IsValidForUpdate());">

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Discovered how to resolve this.

There is a default event handler for the submit event.

Set up the event listeners as normal , however override the default listner via:

document.Form1.onsubmit=DoNoSubmit;

function DoNotSubmit()
{
return false;
}

No you can attach a listener to the click event of the specific button and run validation code.

This way, the validation will execute for that specific button - this is useful if you have multiple submit buttons!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top