Page 1 of 1

js form to element loop

Posted: Tue Aug 24, 2004 12:12 pm
by voltrader
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.

Code: Select all

function postthegoodies(form)
{
	
	
	for(i=0;form.length;i++)
	{
		if(form.elementїi].name=="stateї]")
		{
		for(j=0;j<form.elements&#1111;i].length;j++)
			&#123;
			var1=form.elements&#1111;i].options&#1111;j].selected;
		
			alert(form.elements&#1111;i].value);
			&#125;
		&#125;
	&#125;
	return false;
&#125;
Here's the relevant html:

Code: Select all

<select style="width:100" name=state&#1111;] 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>

Posted: Tue Aug 24, 2004 12:21 pm
by feyd

Code: Select all

<input type=button value="go" name="statego" onclick="alert(this.form.elements&#1111;'state&#1111;]'].options&#1111;this.form.elements&#1111;'state&#1111;]'].selectedIndex].value);">