Link to home
Start Free TrialLog in
Avatar of wendell01
wendell01

asked on

How do I compare a listbox value using JavaScript getElementsByName

I want to compare a value from a form that uses radio buttons for a list box. I am using getElementsByName in my javascript with success for checked boxes and text boxes however I am not having success with list box.
The checked box code looks like
if(document.getElementsByName('SDvcs')[0].checked && document.getElementsByName('SDfprv')[0].checked)

text uses .value and I can't seem to find what to use for list box.
Avatar of nivlam
nivlam
Flag of United States of America image

Could you post the code for the form?
ASKER CERTIFIED SOLUTION
Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wendell01
wendell01

ASKER

I use PHP, HTML form, and MYSQL to process data for a form.

The php functions for insert or update use php below for the data fields we are trying to check.
      // combobox: SDvcs
      $combo_SDvcs = new Combo;
      $combo_SDvcs->ListType = 2;
      $combo_SDvcs->ListBoxHeight = 10;
      $combo_SDvcs->RadiosPerLine = 1;
      $combo_SDvcs->ListItem = explode(";;", "N;;Y");
      $combo_SDvcs->ListData = explode(";;", "N;;Y");
      $combo_SDvcs->SelectName = "SDvcs";
      // combobox: SDfprv
      $combo_SDfprv = new Combo;
      $combo_SDfprv->ListType = 2;
      $combo_SDfprv->ListBoxHeight = 10;
      $combo_SDfprv->RadiosPerLine = 1;
      $combo_SDfprv->ListItem = explode(";;", "N;;Y");
      $combo_SDfprv->ListData = explode(";;", "N;;Y");
      $combo_SDfprv->SelectName = "SDfprv";
The code on the form itself looks like:
                          <td colspan="2" valign=top class=TableBlueHeader>                            <div align="center"><span class="style1"><strong>Validated by carton standards
                        <br>
                        <%%COMBO(SDvcs)%%>
                        </strong> </span></div></td>
                          <td width="120" valign=top class=TableBlueHeader><div align="center"><span class="style1"><strong>Reference Number:</strong></span>
                        <br>
  <td colspan="7" valign=top class=TableBlueHeader>                        <div align="center"><span class="style1"><strong>First Press run validation
                        <br>
                        <%%COMBO(SDfprv)%%>
                        </strong></span></div></td>

I use a function called SDform_validate to process the data fields.



I actually ended up with a simple if statement. The key was realizing I needed to look at the proper index to test for the value to be checked.
if(document.getElementsByName('SDvcs')[2].checked && document.getElementsByName('SDfprv')[2].checked)
I  ended up using the following if statement

if(document.getElementsByName('SDvcs')[2].checked && document.getElementsByName('SDfprv')[2].checked)