I am trying to set a value of a textbox and I get this error... Please see my code:
this is my textbox
<input id="Text1" type="text" runat="server"/>
this is my drop down list
<select id="title" name="D1" onchange="Select()" >
<option selected="selected"></option>
<option value="1">Pilot</option>
<option value="5">Engineer</option>
</select>
And that is my function
<script type="text/javascript">
function Select() {
var ddl = document.getElementById("title");
var selected = ddl.options[ddl.selectedIndex].value;
document.getElementById("Text1").value = selected;
alert(document.getElementById("Text1").value);
if (selected == "5") {
document.getElementById('divTechnician').style.visibility = "visible";
} else {
document.getElementById('divTechnician').style.visibility = "hidden";
}
}
</script>
Error occurs when I try to assign value to this text box
document.getElementById("Text1").value = selected;
I am trying to set a value of a textbox and I get this error... Please see my code:
this is my textbox
<input id="Text1" type="text" runat="server"/>
this is my drop down list
<select id="title" name="D1" onchange="Select()" >
<option selected="selected"></option>
<option value="1">Pilot</option>
<option value="5">Engineer</option>
</select>
And that is my function
<script type="text/javascript">
function Select() {
var ddl = document.getElementById("title");
var selected = ddl.options[ddl.selectedIndex].value;
document.getElementById("Text1").value = selected;
alert(document.getElementById("Text1").value);
if (selected == "5") {
document.getElementById('divTechnician').style.visibility = "visible";
} else {
document.getElementById('divTechnician').style.visibility = "hidden";
}
}
</script>
Error occurs when I try to assign value to this text box
document.getElementById("Text1").value = selected;
Share
Improve this question
edited Jun 12, 2014 at 12:18
Matt K
asked Jun 12, 2014 at 12:02
Matt KMatt K
391 gold badge2 silver badges10 bronze badges
9
-
2
I don't see the
divTechnician
ID anywhere. – user2357112 Commented Jun 12, 2014 at 12:03 - 1 That is irrelevant, divTechnician is not causing problems – Matt K Commented Jun 12, 2014 at 12:05
- I don't get it it's working fine in jsbin – Camille Hodoul Commented Jun 12, 2014 at 12:08
- 1 Please make sure that text box is present on the page at the moment when you're changing selector value. In Chrome developer tools, try executing document.getElementById("Text1"). – KIR Commented Jun 12, 2014 at 12:09
- 1 There is no error in your javascript. – Matt Ellen Commented Jun 12, 2014 at 12:10
1 Answer
Reset to default 2set clientidmode=static to this element
<input id="Text1" type="text" runat="server" clientIdMode="static"/>