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.getElementsByN ame('SDvcs ')[0].chec ked && document.getElementsByName ('SDfprv') [0].checke d)
text uses .value and I can't seem to find what to use for list box.
The checked box code looks like
if(document.getElementsByN
text uses .value and I can't seem to find what to use for list box.
Could you post the code for the form?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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->ListBoxHeigh t = 10;
$combo_SDvcs->RadiosPerLin e = 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->ListBoxHeig ht = 10;
$combo_SDfprv->RadiosPerLi ne = 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>Val idated by carton standards
<br>
<%%COMBO(SDvcs)%%>
</strong> </span></div></td>
<td width="120" valign=top class=TableBlueHeader><div align="center"><span class="style1"><strong>Ref erence Number:</strong></span>
<br>
<td colspan="7" valign=top class=TableBlueHeader> <div align="center"><span class="style1"><strong>Fir st Press run validation
<br>
<%%COMBO(SDfprv)%%>
</strong></span></div></td >
I use a function called SDform_validate to process the data fields.
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->ListBoxHeigh
$combo_SDvcs->RadiosPerLin
$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->ListBoxHeig
$combo_SDfprv->RadiosPerLi
$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>Val
<br>
<%%COMBO(SDvcs)%%>
</strong> </span></div></td>
<td width="120" valign=top class=TableBlueHeader><div
<br>
<td colspan="7" valign=top class=TableBlueHeader> <div align="center"><span class="style1"><strong>Fir
<br>
<%%COMBO(SDfprv)%%>
</strong></span></div></td
I use a function called SDform_validate to process the data fields.
ASKER
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.getElementsByN ame('SDvcs ')[2].chec ked && document.getElementsByName ('SDfprv') [2].checke d)
if(document.getElementsByN
ASKER
I ended up using the following if statement
if(document.getElementsByN ame('SDvcs ')[2].chec ked && document.getElementsByName ('SDfprv') [2].checke d)
if(document.getElementsByN