By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

HTML javascript checkbox issue

P: 4
Here is a piece of html code

[HTML]<form name="package_information" id="package_information" method="post" enctype="multipart/form-data""& lt;"
<tr>
<td><input type="checkbox" name="FormListName" value="31" />Adobe client-server form</td>
</tr>
<tr>
<td><input type="checkbox" name="FormListName" value="32" />Adobe XDP form</td>
</tr>
<tr>
<td><input type="checkbox" name="FormListName" value="29" />Dispute Form (pff)</td>
</tr>
<tr>
<td><input type="checkbox" name="FormListName" value="30" />SSA Form SSA-L996 (pff)</td>
</tr>
<tr>
<td><input type="checkbox" name="FormListName" value="22" />Tax form 1040a (1)</td>
</tr>
<tr>
<td><input type="checkbox" name="FormListName" value="23" />Tax form 1040a (2)</td>
</tr>
<tr>
<td><input type="checkbox" name="FormListName" value="28" />Tax form 1040a User Verification Required</td>
</tr>

.
.
.
.

<input type="button" value="Publish" onClick="javascript:doPackagesubmit();">&nbsp;
</form>
[/HTML]

Here are the relevent javascript functions

Expand|Select|Wrap|Line Numbers
  1. function getFormList()
  2. {
  3.         var formListStr = null;
  4.         var firstIteration = true;
  5.         var formList = document.getElementById("package_information").getElementsByTagName("FormListName");
  6.         if (eval(formList))
  7.         {
  8.             if (eval(formList.length != "undefined"))
  9.             {
  10.                 if (formList.length == 0)
  11.                 {
  12.                      alert("Need to select atleast one form for a explicit package" );
  13.                      switchPage('page4'); switchnav('nav4');
  14.                 }     
  15.  
  16.                 for (i = 0 ; i < formList.length; i++)
  17.                 {
  18.                     if ((formList[i].checked))
  19.                     {
  20.                         if (firstIteration)
  21.                         {
  22.                             formListStr = formListStr+formList[i].value+","
  23.                             firstIteration = false;
  24.                         }else
  25.                         {
  26.                             formListStr = formListStr+formList[i].value;
  27.                         }    
  28.                     }
  29.                 }
  30.             }else
  31.             {
  32.                 if (formList.checked == true)
  33.                 {
  34.                     alert("Only one checkbox is checked");
  35.                 }else
  36.                 {
  37.                     alert("formList is not checked");
  38.                 }
  39.             }    
  40.         }else
  41.         {
  42.             alert("forms list does not exist");
  43.         }    
  44.  
  45.         return formListStr;
  46. }

Javascript function "doPackageSubmit" calls "getFormList".

Now here is my problem, irrepective of how many of the checkboxes i check i always get the message "Need to select atleast one form for a explicit package". What is that ?
May 16 '07 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
Moved from Articles section.

You don't need to use getElementsByTagName. Just use document.form.FormListName to access the checkboxes.
May 16 '07 #2

P: 4
I have tried that too with the same results.
May 16 '07 #3

P: 4
Dunno if this makes a difference but the checkbox buttons are created at runtime. (This is part of jsp code).
May 16 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Does
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("package_information").FormListName
not work? If you do want to use getElementsByTagName, then use "input" (the tag name) instead and then check for the type (checkbox). See link
May 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.