user1690748 user1690748 - 1 year ago 70
HTML Question

<option> value to <input> text value

I am trying to set a input box's value and text from a select element.

var p = document.getElementById("pretestNameSelect");
var test = p.options[p.selectedIndex].value;
if (choice.toString() == "type0")
$(document.getElementById("pretestNameSelectHiddenTextQ0")).value = "test";
$(document.getElementById("pretestNameSelectHiddenTextQ0")).text = "test";

The alert(test) works and shows the correct value but the value is not set and the alert(doc...) shows an empty alert.

What could be the problem?

Answer Source

You are mixing Jquery Selectors with DOM selectors.

You can use



document.getElementById('pretestNameSelectHiddenTextQ0').value = test;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download