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

change input value based on selection tag 1

Status
Not open for further replies.

ttuser4

MIS
Jun 19, 2008
147
CA
I want to change input value based on selection but my code doesn't work. Can you please help me to fix it?

<script type="text/javascript" defer="defer">
...
Function Rafter() {
var dropdownIndex = document.getElementById('tb').selectedIndex;
var dropdownValue = document.getElementById('tb').[dropdownIndex].value;
var changer = document.getElementbyId('rafter');

if dropdownValue = "yes" {
changer.value = "Structural";

else {
changer.value = "Non-structural";
}
}
}
</script>
html
...
<tr>
<td><b>8. Thermally broken:</b> </td>
<td> <select size="1" name="tb" id="tb" onclick="Rafter();">
<option selected value="yes"> Yes </option>
<option value="no"> No </option>
</select>
</td>
<td>Select thermally broken or non-thermally broken.</td>
</tr>
<tr>
<td><b>9. Rafter:</b> </td>
<td> <input type="text" name="rafter" id="rafter" size="15" value="Structural" READONLY/></td>
<td>Structural or non-structural rafter.</td>
</tr>
...
 
Many things wrong with that code try this:

Code:
<script type="text/javascript" defer="defer">
function Rafter(){
var dropdownValue = document.getElementById('tb').value;
var changer = document.getElementById('rafter');

      if  (dropdownValue == "yes")    {
         changer.value = "Structural";
}

      else {
         changer.value = "Non-structural";
         }
      
}
</script>

and change the even in your drop down form OnClick to onChange so that it fires when the value changes, not merely when you click on the drop down.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top