Reputation: 25
I have been looking pretty hard for an answer to this and have attacked it from my code and from basic browser set up. What I am trying to do is have a text field change based on what a select box is set to. What I have put together thus far does exactly what I want it to do in all browsers but Explorer. Is there anything further I need to declare to achieve this or is there another method that would be better for my end goal?
This is what i have at the moment.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function changeusf()
{
document.getElementById("usf").setAttribute("value",optionsusf.value);
}
</script>
</head>
<body>
<input type="text" value="" name="usf" id="usf"/>
<select id="optionsusf" name="optionsusf" onchange="changeusf()">
<option value="--------------------">Select One</option>
<option value="0.00">No Tax</option>
<option value="0.18">18% Tax</option>
<option value="0.07">7% Tax</option>
</select>
</body>
</html>
Thank you in advance for your time.
Upvotes: 1
Views: 1203
Reputation: 10220
1.add the following jquery code in changeusf
function
$("#usf").val($("#optionsusf option:selected").text())
Remember to include jquery .
Upvotes: 0
Reputation: 2921
Try this :
<select id="optionsusf" name="optionsusf" onchange="changeusf(this.value);">
<option value="--------------------">Select One</option>
<option value="0.00">No Tax</option>
<option value="0.18">18% Tax</option>
<option value="0.07">7% Tax</option>
</select>
function changeusf(val)
{
document.getElementById("usf").value = val;
}
In this we are using simple JavaScript
to pass the value onchange
of select box
to the function and in that function we are just receiving the value and putting it in textbox
. So we are not using anything which creates any problem in any browser
.
Upvotes: 1
Reputation: 66663
You should be just doing:
document.getElementById("usf").value = document.getElementById("optionsusf").value;
instead of using setAttribute
Upvotes: 1