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

Alert on Checkbox Error

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I have a series of checkboxes all with the same name of CITY. I am trying to come up with a way to give an alert if at least one is not checked and/or no keyword is entered into a text area.&nbsp;&nbsp;I'm not sure how to begin with the check box question.&nbsp;&nbsp;The form tag name is always &quot;CITY&quot; but the form value is different with each one.&nbsp;&nbsp;For example:<br><br>&lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'City1'&quot;&gt;City1<br>&lt;input type=&quot;checkbox&quot; name=&quot;CITY&quot; value=&quot;'City2'&quot;&gt;City2<br><br>Right now, I have an alert for the standard Keyword page (thanks to the help from this site!) but now I need to add another statement for the above.&nbsp;&nbsp;Here is what I have now, but I'm not sure where to add the second alert, which will have different wording:<br><br>&nbsp;function OnSubmitKw(form){<br>&nbsp;if (form.Keywords.value==&quot;&quot; && form.searchtype.value==&quot;Keyword&quot;){<br>&nbsp;alert(&quot;You did not enter any Keywords! Please try again.&quot;);<br>return false;<br>}<br>}<br><br>DonP
 
So far, I have this little alert routine but am having trouble with the part to see if one or more of the City checkboxes are selected. It should pup up the alert only if both Keywords and Cities are not entered/selected but should submit if one or the other or both is.&nbsp;&nbsp;Also, I'm not sure if it needed a nested &quot;if&quot; statement, but it seemed to make more sense with it.<br><br>function OnSubmitCity(form){<br>&nbsp;&nbsp;&nbsp;if (form.searchtype.value==&quot;City&quot;){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (form.checkbox.city==&quot;&quot; ¦¦ form.Keywords.value==&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! Please try again.&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>}<br>}<br>}<br><br>I know the form.checkbox.city==&quot;&quot; isn't right, but I can't seem to figure out what to use instead, especially since all the form checkboxes for city have&quot; city&quot; as their form name, but the value for each is different.&nbsp;&nbsp;Can anyone help?&nbsp;&nbsp;Thanks!<br><br>DonP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top