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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list menu to change text field 1

Status
Not open for further replies.

mikemedia

Programmer
Apr 28, 2006
39
US
I've done it before, but now I'm bumbling.
Need to change text field based on option selected in list menu.

What have I done wrong? Please, need quick answer!

<script language="JavaScript" type="text/javascript">
function whichTest() {
if(document.getElementById('rank').option.selected.value = "Private" || "PFC" || "LCpl" || "Cpl" || "Sgt" || "GS01" || "GS02" || "GS03" || "GS04" || "GS05" || "GS06" || "GS07" || "GS08")
{
document.getElementById('whichTest').value = "EmpTest";
} else {
document.getElementById('whichTest').value = "SupvTest";
}
}
</script>
 
comparison is == not =, and if you wanna do this comparison your going to have do something like
Code:
var rank = document.getElementById('rank').option.selected.value 
if(rank == "Private"||rank=="somethingelse"{
 do something
}


I would rather do something like
Code:
var rankreg = /Private|PFC|LCpl|Cpl|Sgt|GS[0][1-9]/;
rankreg.test(document.getElementById("rank").value);
 
What th' heck am I doin' wrong?!?

Revised script in order to keep it REAL SIMPLE. Still, Nada!

Code:
<head>
<script language="JavaScript" type="text/javascript">
function whichTest() {
var rank = document.form1.getElementById('rank').option.selected.value 
	if(rank == "Private")
	{
 		alert("OK!");
	} 
}  
</script>  
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <select name="dropper" id="dropper" onChange="whichTest()">
      <option value="null" selected="selected"></option>
      <option value="you">you</option>
      <option value="me">me</option>
      <option value="them">them</option>
      <option value="Private">Private</option>
    </select>
  </p>
</form>
</body>
</html>
 
>var rank = document.form1.getElementById('rank').option.selected.value
[tt]var rank = document.form1.dropper.value;[/tt]

Or if you have some reminiscence of selected something and want to use it, it is this.

[tt]var rank = document.form1.dropper.options[document.form1.dropper.selectedIndex].value;[/tt]

But, it becomes clumsy.
 
Thank you.

Your assist was exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top