|
-
Dec 8th, 2003, 01:00 PM
#1
Thread Starter
Hyperactive Member
Update or Cancel?
I have the following code:
Code:
<form name="rar" method=post action="update.asp" onsubmit="return validate()">
<input name="update" type="submit" value="Cancel">
<input name="update" type="submit" value="Update" >
</form>
how can I detect if the user has pressed Cancel or Update within the validate function (i.e. onsubmit="return validate()")?
Cheers!
-
Dec 8th, 2003, 01:06 PM
#2
Frenzied Member
make cancel a normal button (not submit) and make it run a different function which does something different. If you want it to clear the form make it a reset button.
Have I helped you? Please Rate my posts. 
-
Dec 8th, 2003, 01:15 PM
#3
Thread Starter
Hyperactive Member
I still want the form to submit even though I pressed the cancel button... but I do not want the validation code to execute...
Is that possible?
It would be great if I could have something like this in the validation function:
Code:
if (submit button is update){
do validation stuff
if (validation went OK){
return true
}
else{
return false
}
}
else{
return true//so that the form can submit...
}
Think this is probably not the best way to do it, but the ASP page that this is going to expects the request.form("update") = "Cancel"
to be true if the cancel button was pressed :P
The "if (submit button is update){" part is the bit I am having trouble with...
Cheers
[added later - I think the problem is that the value of the submit button is not given until the submite has taken place. Any ideas if this is correct?]
Last edited by chuddy; Dec 8th, 2003 at 01:25 PM.
-
Dec 8th, 2003, 01:50 PM
#4
Quite correct, I don't think there's a cross-browser way to find the submit button pressed. Which means you should move your validation code (or parts thereof) to an onclick handler of the normal submit button.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 8th, 2003, 02:23 PM
#5
Thread Starter
Hyperactive Member
but if I do this then how can I specify that I do not want the form to submit if the validation fails?
<form name="rar" method=post action="update.asp" onsubmit="return validate()">
i.e. I need an equivalent to the "return" in the above code...
hmmm... think I may end making the cancel button a "go back" button :P
-
Dec 8th, 2003, 02:31 PM
#6
Frenzied Member
how about this:
Code:
var bool = true
if (button was submit)
do validation
if (validation went ok)
else
var bool = false
end if
end if
if (bool == true) //If cancel was pressed or validation passed ok.
document.MyFrm.submit() //This will submit the form.
end if
make both buttons normal buttons. This function will submit the form anyway.
Have I helped you? Please Rate my posts. 
-
Dec 8th, 2003, 02:52 PM
#7
Do return validate() in the onclick of the submit button. If validate returns false, the click has no effect.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 9th, 2003, 03:17 AM
#8
Fanatic Member
just make one function called from onclick of the update button, dont bother with the function at all when pressing cancel. he said he wanted it to submit without validating so it doesnt need to be part of a function.
-
Dec 9th, 2003, 04:53 AM
#9
Thread Starter
Hyperactive Member
Thanks for all the replies!
All very useful stuff.
I didn't know that it was possible to submit the form just by calling it's submit() method... great stuff.
Again, thanks Acidic, Cornedbee and davebat!
-
Dec 9th, 2003, 07:07 AM
#10
I often have problems submitting a form with submit(). In particular, I think IE won't submit a form via the submit() method if it has an absolute target URL.
Or something like that.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|