21
rated 0 times
[
28]
[
7]
/ answers: 1 / hits: 17164
/ 11 Years ago, fri, august 2, 2013, 12:00:00
I'm trying to change a value from a select tag using JavaScript. Let's say that I have this textbox, and if that textbox is null, no changes will be done and the value of the select tag options will be as is. But if that textbox is filled, then I have to assign a different value aside from the ones in the select tag options.
Here's what I'm trying to do:
HTML:
<input type=text id=txtTest />
<select name=rdoSelect id=rdoSelect>
<option value=option1>Option 1</option>
<option value=option2>Option 2</option>
</select>
JavaScript:
if (document.getElementById('txtTest').value===null)
{
document.getElementById('rdoSelect').value;
}
else
{
document.getElementById('rdoSelect').value = option 3;
}
I can't make it work. I've tried pointing it to an element/variable rather than to a value and it still doesn't work:
var test = document.getElementById('rdoSelect');
test.value = option 3;
I need help, please. Thanks!
More From » select