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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you validate a checkbox in a form using OnSubmit?

Status
Not open for further replies.

Joe2k

Programmer
Jul 17, 2000
14
CA
Hi,<br><br>My problem is that I need a script that will make sure at least 1 of the 6 checkboxes are selected before being sent.&nbsp;&nbsp;This is the top part of the form, and I have all the other validations working except for the checkboxes.&nbsp;&nbsp;Here is what I have so far:<br><br>ONSUBMIT=&quot;<br>if (this.councillor1.checked == FALSE)<br>{<br>return true<br>}<br>else if (this.councillor2.checked == FALSE)<br>{<br>return true<br>}<br>else if (this.councillor3.checked == FALSE)<br>{<br>return true<br>}<br>else if (this.councillor4.checked == FALSE)<br>{<br>return true<br>}<br>else if (this.councillor5.checked == FALSE)<br>{<br>return true<br>}<br>else if (this.councillor6.checked == FALSE)<br>{<br>alert('Please select a councillor')<br>return false<br>} <br>else if (this.Subject.value == '')<br>{<br>alert('Please enter a title for the subject')<br>return false<br>}<br>etc.....<br><br>So what I need is it to read down the script and if does not read a selected checkbox, a alert message pops up saying that they need to make a selection.<br><br>Thanks a ton,<br><br>Joe<br>
 
this from my other answer:<br><br>I would write the code like so (but im in a hurry :)<br><br>if(thecheckbox.checked){return true}<br>if(thecheckbox1.checked){return true}<br>if(thecheckbox2.checked){return true}<br>if(thecheckbox3.checked){return true}<br>...<br>window.alert(&quot;please choose an item&quot;)<br>return false;<br><br>you could probably cycle through an array also... <br><br>if(form.elements.checked){return true}<br><br>...depending on the form<br><br>- <A HREF="mailto:jared@aauser.com">jared@aauser.com</A><br>
 
It still does not work.&nbsp;&nbsp;Now all it does is skip all my validations.&nbsp;&nbsp;This is what it looks like now:<br><br>ONSUBMIT=&quot;<br>if (councillor1.checked)<br>{<br>return true<br>}<br>if (councillor2.checked)<br>{<br>return true<br>}<br>if (councillor3.checked)<br>{<br>return true<br>}<br>if (councillor4.checked)<br>{<br>return true<br>}<br>if (councillor5.checked)<br>{<br>return true<br>)<br>if (councillor6.checked)<br>{<br>return true<br>}<br>else<br>{<br>alert('Please select a councillor')<br>return false<br>} <br>else if (this.Subject.value == '')<br>{<br>alert('Please enter a title for the subject')<br>return false<br>}<br>other varlidations .......<br><br><br>Does anyone know why it doesn't work?&nbsp;&nbsp;Help!<br><br>Thanx,<br><br>Joe<br>
 
Can anyone help me?&nbsp;&nbsp;Please!
 
Create a hidden input within the form to serve as a indicator if a choice has been selected.<br><br>&lt;input type='hidden' name='radioPickedOk' value='0'&gt;<br><br>In your form have the following:<br>&lt;form id='whatever&quot; name=&quot;whatever&quot; action=&quot;ValidateForm&quot;&gt;<br><br>&lt;input type='radio' name='councillor' value='councillor1' OnClick=&quot;&quot;document.whatever.radioPickedOk.value='1';&gt;<br><br>&lt;input type='radio' name='councillor' value='councillor2' OnClick=&quot;&quot;document.whatever.radioPickedOk.value='1';&gt;<br><br>&lt;input type='button' value='Update' onClick=&quot;&quot;validateFields(this.form);&quot;&quot;&gt;<br>&lt;/form&gt;<br><br>In the header of your page include the following JavaScript:<br>&lt;script language=&quot;javascript&quot;&gt;<br>{<br>&nbsp;function validateFields(f)<br>&nbsp;&nbsp;if (f.radioPickedOk.value == '0')&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;{ alert(&quot;Please Select a Choice.&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;{ f.submit();<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>&lt;/script&gt;<br>
 
You could do that without a hidden field as well, jsut a global variable. Thats a good idea, but there is one problem. The onClick event will fire even if they are clicking the check box to uncheck it (so if i click the yes box and than click it again, it is no longer checked, but my variable thinks so). What you really need is a function that is called onClick that checks to see if it unchecked and then sets the variable accordingly (if its checked and being clicked, make the controller variable false).<br><br><A HREF="mailto:jared@aauser.com">jared@aauser.com</A>
 
I'm working on the same problem and have another post about it. But I am confused by the above (I know HTML very well, but know little about JavaScript).&nbsp;&nbsp;How is the form submitted to my processing script if it has a form tag like:<br>&lt;form id='whatever&quot; name=&quot;whatever&quot; action=&quot;ValidateForm&quot;&gt;<br>Doesn't the action have to be the script that processes the form, which in this case is a VBscript?<br><br>It looks like the right idea though, but I have not been able to get it to work on my file.<br><br>Don
 
I'm trying to get a checkbox validation to work but seem to be missing something. This was taken from various posts here on tek-tips so I've probably gotten something mixed up. Can anyone help?<br><br>The HTML form includes a number of check boxes with the same name=&quot;CITY&quot; value similar to this one:<br><br>&lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'Campbell'&quot; OnClick=&quot;form.CITY.checkboxPickedOk.value='1';&quot;&gt;<br><br>The form tag itself is:<br>&lt;form name=&quot;city&quot; method=&quot;post&quot; action=&quot;cgi-bin/search.asp&quot; OnSubmit=&quot;return OnSubmitCity(this)&quot;&gt;<br><br>And a hidden tag:<br>&lt;input type=&quot;hidden&quot; name=&quot;checkboxPickedOk&quot; value=&quot;0&quot;&gt;<br><br>I want it to submit if there is either a keyword entered or a city selected (or both). The alert JavaScript code is:<br>&nbsp;function OnSubmitCity(form){<br>&nbsp;&nbsp;&nbsp;if (form.Keywords.value==&quot;&quot; ¦¦ form.CITY.checkboxPickedOk.value==&quot;0&quot;){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;You did not select any Cities and/or Keywords!\n\nPlease try again . . .&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>}<br>}<br><br>The search button is plain HTML:<br>&lt;input type=&quot;submit&quot; value=&quot;Begin Search&quot;&gt;<br><br>Thanks!<br><br>Don
 
joe2k : f course it skips all your validation as as soon as one is checked you return true = you go out of the function<br><br>have to do something like : <br>if (!c1.checked&&!c2.checked&&...&&!c6.checked) <br>&nbsp;&nbsp;alert(&quot;you have to check at least one checkbox thank you&quot;)<br>return true<br><br>sure it does work<br>no need of any hidden field or what !!!<br>
 
DonP : the point is that all your checkboxes have the same name !!<br>what you have to do is first to create DIFFERENT checkboxes, let's say one per city, something like :<br>&nbsp;&nbsp;&lt;input type=&quot;checkbox&quot; name=&quot;Campbell&quot; value=&quot;Campbell&quot;&gt;<br>&nbsp;&nbsp;&lt;input type=&quot;checkbox&quot; name=&quot;Paris&quot; value=&quot;Paris&quot;&gt;<br>then : <br>&quot;I want it to submit if there is either a keyword entered or a city selected (or both).&quot;<br><br>function OnSubmitCity(form){<br>&nbsp;&nbsp;&nbsp;if (form.Keywords.value==&quot;&quot; ¦¦ (!form.Campbell.checked&&!form.Paris.checked&&!...))<br>&nbsp;&nbsp;&nbsp;alert(&quot;hey you have to enter at least ...&quot;);<br>return true;<br>}<br><br>it DOES work ;]<br><br><br>
 
DonP : what you missed in ChrisQuick's post is that he was using RADIO button - NOT checkboxes !!!!!!<br><br>ChrisQuick : i don't think you actually NEED the hidden field <br><br>
 
iza, Actually I saw that Radio Buttons were being referred to but the title of this thread is for Checkboxes.&nbsp;&nbsp;I presumed since that's the case, that it would work for both.<br><br>DonP
 
iza, Unfortunately I do not have the option of renaming the checkboxes.&nbsp;&nbsp;They all need to be &quot;CITY&quot; to work with the VBscript that precesses them.&nbsp;&nbsp;Otherwise, it would have to be rewritten and I dan't have the skills (or time) to do that, especially since we are a small non-profit community service company.<br><br>Even though I am not a programmer, I can't understand what difference it could make since logically, I would think that if one or more were checked but had the same value, as long as that value showed as checked (or not) it could be passed into the JavaScript so an alert would appear if nothing were selected.&nbsp;&nbsp;Does that make sense or am I out in left field in the way I'm thinking?<br><br>The Alert is working if I don't enter a Keyword, but I need to be able to select a city or cities without a keyword and have it submit too.&nbsp;&nbsp;I need the alert if a city is NOT checked, by the way, not if it is.
 
ok, you just don't get the diff between checkboxes & radiobuttons : <br>* CHECKBOX places a toggle switch on an HTML form, letting the user set a value on or off.<br>* RADIO places a radio button on an HTML form. Radio buttons can be grouped into sets, and only one button per set can be selected at a time<br>[both from the netscape developper's doc]<br><br>--&gt; so if you have many checkboxes with the same name, it can be tough to know which one is actually on or off<br>--&gt; i think you should use RADIOBUTTONS : they all have the same name and different values, and the user can only select one, so it's easy to know which one is selected<br><br>then your code is :<br>&nbsp;&nbsp;&lt;input type=&quot;<font color=red>radio</font>&quot; name=&quot;<font color=red>city</font>&quot; value=&quot;<font color=red>Campbell</font>&quot;&gt;<br>&nbsp;&nbsp;&lt;input type=&quot;<font color=red>radio</font>&quot; name=&quot;<font color=red>city</font>&quot; value=&quot;<font color=red>Paris</font>&quot;&gt;<br>...<br>function OnSubmitCity(form){<br>&nbsp;&nbsp;&nbsp;if (form.Keywords.value==&quot;&quot; ¦¦ (form.city.value=''))<br>// the selected city (if one) is form.city.value - so if it's empty no city at all is selected<br>&nbsp;&nbsp;&nbsp;alert(&quot;hey you have to enter at least ...&quot;);<br>return true;<br>}<br><br><br>
 
iza, Thanks, but I DO understand the difference between radio buttons and checkboxes.&nbsp;&nbsp;That's why I am using checkboxes!&nbsp;&nbsp;A user must be able to make multiple selections so that searches can be done of several cities together, which is why they MUST have the same name=city value.&nbsp;&nbsp;That is how the search VBscript is coded and I don't have the option to rewrite it.&nbsp;&nbsp;It would mean writing some very complicated SQL statements if each city had a different name value.&nbsp;&nbsp;All I need to do is to have an alert when a checkbox (any checkbox) is NOT selected and/or when a keyword is NOT entered.&nbsp;&nbsp;As long as the JavaScript is NOT getting the name=city value, it should give an alert since there will be no alert if one or more IS checked (or if a Keyword is entered).<br><br>Maybe you can suggest how to do it if I had only ONE checkbox and a Keyword tag and forget that there are multiple ones.&nbsp;&nbsp;Does that make it any easier?<br>&nbsp;<br>Right now, I have a workaround built into the VBscript when there are no entries but I don't want the error message to be on the server side.&nbsp;&nbsp;Our server needs all the help it can get.&nbsp;&nbsp;With the JavaScript alert I presented above, it is giving an alert but is requiring a Keyword, which is not desirable.&nbsp;&nbsp;I want to be able to simply list the database contents of a city without having to enter a Keyword if that's what the user desires.<br><br>How about something like this in each city checkbox tag:<br>onClick=&quot;city=1&quot;<br>onClick=&quot;city=2&quot; ...etc<br><br>And then something like this in the JavaScript alert (I know the syntax is all wrong - this is just the general idea):<br><br>function OnSubmitCity(form){<br>&nbsp;&nbsp;&nbsp;&nbsp;for (i=0;i&lt;document.CITY.city.length;i++){<br>&nbsp;&nbsp;&nbsp;&nbsp;if (document.CITY.city<i>.checked==true)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city=i<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;if (form.Keywords.value==&quot;&quot; ¦¦ city==&quot;&quot;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;You did not select any Cities and/or Keywords!\n\nPlease try again . . .&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>}<br>}<br><br>I gleaned this from another site that goes into great detail about radio buttons and&nbsp;&nbsp;checkboxes with an example of checkboxes that have the same name value, though I'm not sure how to impliment it on my site with my alert.&nbsp;&nbsp;Based loosely on this, maybe you can suggest what needs to be done.<br>Here's the URL to the site:<br><A HREF=" TARGET="_new"> in advance for any more suggestions or ideas, keeping in mind that this thread is about Checkboxes, not Radio Buttons.<br><br>Don
 
ok i got it<br>so either <br>--------------------------------------------<br>you have to use the document.your_form_name.elements array and do something like : (it's what jaredn told you at the 1st answer !!!!!)<br>&nbsp;var is_a_checkbox_checked=false<br>&nbsp;var element_array=document.your_form_name.elements<br>&nbsp;for (var i=0; i&lt;element_array.length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (element_array<i>.type=='check') // not sure of the name of the type but you can check on the doc ;]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(element_array<i>.checked) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is_a_checkbox_checked=true<br>&nbsp;&nbsp;}<br>and now, is_a_checkbox_checked is false if none is checked, whatever the name they can have !!!<br>i'm sure there's a faster / clever / more elegant way to do it but ..<br>--------------------------------------------------------<br>or <br>just create a var that is FALSE when you load the page<br>(a not very nice way but it works : &lt;body onload=&quot;javascript:var test=false;&quot;&gt;)<br>and then if any check box is checked set it to true<br>be careful that when a checkbox is UNchecked the onclick event fires as well !<br>so an idea is : &lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'Campbell'&quot; OnClick=&quot;if (this.checked) test=true else test=test&false&quot;&gt;<br>--------------------------------------------------------<br><br>hope that helps !!!<br><br><br>
 
iza, Thanks! Actually I tried that since it appears to be exactly what I need but, since I am not a programmer, I couldn't get it to work because it was written generally rather than specifically, especially since I need to take into account the Keyword tag.&nbsp;&nbsp;I'm not even sure where I need to put it!&nbsp;&nbsp;But I'll give it another go since it does appear to be what I need. Maybe I'll get lucky this time uness someone can help with specifics!<br><br>Don
 
Hey Don,<br><br>Well I started this message string and I hope to stop it.&nbsp;&nbsp;I had the same problem as you.&nbsp;&nbsp;But everyone that messaged came close to making it work.&nbsp;&nbsp;So I had to just write it myself.&nbsp;&nbsp;So here is the script I use to make sure at least one of the checkboxes is selected:<br><br><br>&lt;input type=&quot;checkbox&quot; name=&quot;MayorCouncil&quot; value=&quot;AllCouncil&quot; onClick=&quot;<br> if (Mayor.checked ¦¦ <br> Councillor1.checked ¦¦ <br> Councillor2.checked ¦¦ <br> Councillor3.checked ¦¦ <br> Councillor4.checked)<br> {<br> alert('To select Mayor & Council, please de-select the councillors you have checked')<br> return false<br> }<br> else (MayorCouncil.checked)<br> {<br> return true<br> }&quot;&gt;<br><br>Ok for me MayorCouncil was the last checkbox in my list.&nbsp;&nbsp;So the script just reads down the checkboxes and see's if they are selected ot not.&nbsp;&nbsp;The only weird thing is that this script only worked when it was as the bottom of my validation script.&nbsp;&nbsp;I don't know why but I don't care cause this works.&nbsp;&nbsp;Anyway I hope this helps<br><br>Joe
 
Joe2k, Thanks! I appreciate everyone's help and have tried all the suggestions so far. Your code is basically what I'm looking for and I had already tried it too, but it seems to require the checkbox be checked rather than unchecked for the alert.&nbsp;&nbsp;To reverse it, I tried:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (form.Keywords.value==&quot;&quot; ¦¦<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city1.unchecked ¦¦ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city2.unchecked ¦¦ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>With form tags like this:<br>&lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'Campbell'&quot; onClick=&quot;city=1&quot;&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'Cupertino'&quot; onClick=&quot;city=2&quot;&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'Gilroy'&quot; onClick=&quot;city=3&quot;&gt;<br><br>But either way, I get the alert unless I enter a Keyword!&nbsp;&nbsp;I think it's almost there but not quite.&nbsp;&nbsp;Maybe I just put my alert and Keyword line in the wrong place . . . <br><br>Don<br>
 
Don,<br><br>I don't think you have have the onClick variable in the script I wrote.&nbsp;&nbsp;There you have to put the name of the checkbox.&nbsp;&nbsp;So in your case you would put &quot;CITY&quot;.&nbsp;&nbsp;Now that I think of it I am not sure my script will work cause all of your checkboxes have the same name.&nbsp;&nbsp;But try putting &quot;CITY&quot; in, see if that works.<br><br>Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top