此声明未给我在selectonemenu框中选择的值:
document.getElementById("purchaseOrderForm:supplierName").value;
怎么做?
答案 0 :(得分:2)
似乎对我有用
<form>
<select id="purchaseOrderForm:supplierName">
<option value="value 1">value 1 </option>
<option value="value 2">value 2 </option>
<option value="value 3">value 3 </option>
</select>
<input type="button" id="btn_showValue" value="show value"/>
</form>
document.getElementById("btn_showValue").onclick = function(){
console.log(document.getElementById("purchaseOrderForm:supplierName").value)
}
答案 1 :(得分:0)
您可以尝试以下内容。 Example
HTML
<form>
<select id="purchaseOrderForm:supplierName">
<option value="1">Order 1 </option>
<option value="2">Order 2 </option>
<option value="3">Order 3 </option>
</select>
<input type="button" id="submit" value="submit" onclick="getvalue();"/>
</form>
的Javascript
function getvalue()
{
var e = document.getElementById("purchaseOrderForm:supplierName");
var str = e.options[e.selectedIndex].value; //the value of the selected option
alert(str);
var e = document.getElementById("purchaseOrderForm:supplierName");
var str = e.options[e.selectedIndex].text; //the text of the selected option
alert(str);
}