js form to element loop

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
voltrader
Forum Contributor
Posts: 223
Joined: Wed Jul 07, 2004 12:44 pm
Location: SF Bay Area

js form to element loop

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);">
Post Reply