HTML DOM value Property
Complete Option Object Reference
Definition and Usage
The value property sets or returns the value of the option (the value to be sent to the
server).
Syntax
optionObject.value=somevalue
|
Example
The following example returns the value of the selected option in a dropdown
list:
<html>
<head>
<script type="text/javascript">
function alertValue()
{
var x=document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].value);
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option value="apple">Apple</option>
<option value="orange">Orange</option>
<option value="pineapple">Pineapple</option>
<option value="banana">Banana</option>
</select>
<br /><br />
<input type="button" onclick="alertValue()"
value="Alert selected value">
</form>
</body>
</html>
|
Try-It-Yourself Demos
Return the
value of a selected option in a dropdown list
Complete Option Object Reference
Whether you're new to XML or already an advanced user, the user-friendly views
and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to
meet your XML and Web services development needs from start to finish.
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- Support for Office Open XML (OOXML)
- Graphical WSDL editor & SOAP debugger
- Java, C#, C++ code generation
- And much more!
Download a fully functional free 30-day trial today!
|