JavaScript Forum JS Made Easy: Free JavaScripts Tutorials Example Code
About This Product
FontsMadeEasy.com
 
The Business Internet
Find it on This page:
 
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet

     
Jsmadeeasy Forums Home   Search   Login   Register   Member List  
JS Made Easy  > JavaScript programming  > Re:  
 
Display using:  
Previous Thread :: Next Thread 
 Author Thread: Submit form on checkbox OnClick
jtrigsby is not online. Last active: 7/28/2004 3:52:08 PM jtrigsby
Top 100 Poster
Joined: 28 Jul 2004
Total Posts: 2
 
Submit form on checkbox OnClick
Posted: 21 Feb 2002 03:19 PM
I'd like to have my form automatically submit when the user checks a checkbox but can't seem to find any info on how to do that.

Any takers? Thanks in advance.

Thom

Admin is not online. Last active: 12/1/2005 12:27:12 PM Admin
Top 25 Poster
Forum Moderator
Joined: 28 Jul 2004
Total Posts: 15
 
Re:
Posted: 21 Feb 2002 04:59 PM
Try This
<form name="frm">
<input type="radio" name="test" onclick="javascript:document.frm.submit();">
</form>

Hope this helps.

Steve

Admin is not online. Last active: 12/1/2005 12:27:12 PM Admin
Top 25 Poster
Forum Moderator
Joined: 28 Jul 2004
Total Posts: 15
 
Re:
Posted: 21 Feb 2002 05:02 PM
Opps you said checkbox not radio here is the one for the checkbox
<form name="frm">
<input type="checkbox" name="test" onclick="javascript:document.frm.submit();">
</form>

I am not sure if this matters to you or not but pay attention that since I am raising "Onclick" event the form will be submited even if the user is trying to uncheck the box.

You can do it differently.
Something like this:
Onclick call function()
in the function see if the box is checked or unchecked and if it is ten do submit.

Just a suggestion.


jtrigsby is not online. Last active: 7/28/2004 3:52:08 PM jtrigsby
Top 100 Poster
Joined: 28 Jul 2004
Total Posts: 2
 
Re:
Posted: 22 Feb 2002 08:31 AM
Thanks! That worked great, except...

there's a new twist.

I've got a js function to validate my form called validate(). I've had it in place using this syntax:

<form name=OrderForm ... OnSubmit="validate();return returnVal;">

When I implemented your suggested script, the OnClick worked fine however, now it doesn't fire the form's OnSubmit.

So I combined the two in the checkbox's OnClick so that it looked something like this:

<input type=checkbox name=chkcopy OnClick="validate();return returnVal;document.testform.submit();">

This syntax will fire the validate() and will uncheck the checkbox if the validation fails (that's a good thing). But if it passes validation it will not submit the form.

My best guess toward a solution is to create a function that can be called by the checkbox's OnClick that does both the validate() and the form submit but I'm completely lost as to how to accomplish that.

Any suggestions / help would be GREATLY appreciated.

Thom



Admin is not online. Last active: 12/1/2005 12:27:12 PM Admin
Top 25 Poster
Forum Moderator
Joined: 28 Jul 2004
Total Posts: 15
 
Re:
Posted: 22 Feb 2002 09:32 PM
Here is what you do.

function validate(){
validation goes here
if validation is good then
document.formname.submit() = "/filename.asp"
else
return false dont submit
}


with this code do not put onsubmit in the <form> tag.

<input type=checkbox name="sample" Onclick=validate()>

See if this helps

Previous Thread :: Next Thread 
Goto to page:  Prev Next
 
Jsmadeeasy.com  > JS Made Easy  > JavaScript programming  > Re: