Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit the Scope of onChange 1

Status
Not open for further replies.

fpwr

Programmer
Oct 21, 2003
95
US
I've got a form page where I'm using [tt]onChange[/tt] in a [tt]Select[/tt] statement to update an [tt]input[/tt] field. My problem is that instead of just updating the one field it is updating everything and I can't seem to limit it for whatever reason. Maybe it needs some kind of ID or something???

Here's a demo snippet:

Code:
<script language=JavaScript>

function makechange() {

	if (document.myForm.mySelect_1.value='Change') document.myForm.blahText_1.value='Changed Text';
	if (document.myForm.mySelect_2.value='Change') document.myForm.blahText_2.value='Changed Text';
	if (document.myForm.mySelect_3.value='Change') document.myForm.blahText_3.value='Changed Text';
}

</script>

<body>
<form name="myForm">

	<select name="mySelect_1" onChange="makechange();">
		<option value="Original" SELECTED>Original</option>
		<option value="Change">Change the Original Value</option>
		<option value="No_Change">Don't Change the Original Value</option>
	</select>
	<input type="text" name="blahText_1" value="Original Text"><br><br>

	<select name="mySelect_2" onChange="makechange();">
		<option value="Original" SELECTED>Original</option>
		<option value="Change">Change the Original Value</option>
		<option value="No_Change">Don't Change the Original Value</option>
	</select>
	<input type="text" name="blahText_2" value="Original Text"><br><br>

	<select name="mySelect_3" onChange="makechange();">
		<option value="Original" SELECTED>Original</option>
		<option value="Change">Change the Original Value</option>
		<option value="No_Change">Don't Change the Original Value</option>
	</select>
	<input type="text" name="blahText_3" value="Original Text">

</form>
</body></html>

Any insight would be appreciated! Thanks.

Paul.
 
Your JavaScript if-statements are using single equals signs, thereby setting the value of each thing to the String specified.

Use double-equals (==) for conditionals.

--Dave
 
Grrr....it's been a long day. [dazed] Thanks!
 
Heheh - if I had a penny for ever time I'd done that ... ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top