js form to element loop
Posted: Tue Aug 24, 2004 12:12 pm
I have 2 list boxes on the screen. The first one is populated with state abbreviations using php. I'd like to pick up the value of the state, on press of "go" button and use that to populate the second box with cities.
I'm having trouble with the js. Lack of displayed runtime errors is a pia!
Reason I loop through the entire form is that user can press more than one "go" button.
Here's the relevant html:
I'm having trouble with the js. Lack of displayed runtime errors is a pia!
Reason I loop through the entire form is that user can press more than one "go" button.
Code: Select all
function postthegoodies(form)
{
for(i=0;form.length;i++)
{
if(form.elementїi].name=="stateї]")
{
for(j=0;j<form.elementsїi].length;j++)
{
var1=form.elementsїi].optionsїj].selected;
alert(form.elementsїi].value);
}
}
}
return false;
}Code: Select all
<select style="width:100" name=stateї] multiple class=text>
<option selected value='0'>AK</option>
<option value='1'>AL</option>
<option value='2'>AR</option>
<option value='3'>AZ</option>
<option value='4'>CA</option>
<option value='5'>CO</option>
<option value='6'>CT</option>
</select>
<td width=100>
<input type=button value="go" name="statego" onclick="return postthegoodies(document.browse);">
</td>