- Forums
- Javascipt
- Javascript - Get Select Option Value Form
this small code shows you how you can get the value of a select option field and use it in your javascript. this is helpful if you are writting ajax form [2228], Last Updated: Mon Jun 24, 2024
Webune Support
Mon Aug 02, 2010
0 Comments
536 Visits
if you are a beginner javascript programmer, you might find this short tutorial helpful.
this small code shows you how you can get the value of a select option field and use it in your javascript. this is helpful if you are writting ajax form
1. step one is to open your text editor. i am using windows, so i will use notepad. copy and paste this code into a blank notepad:
<!--
############## CREATED BY WWW.WEBUNE.COM ###############
############## COPYRIGHT UGN/GPL 2010 #################
############# PLEASE DO NOT REMOVE THIS ###############
-->
<p>This small script shows you how to get the javascript value in a web form.<br /></p>
<script type="text/javascript">
function alertselected(){
var Field = document.getElementById('sample');
alert('Tab index = ' + Field.selectedIndex + ' \n value = ' + Field.value + ' \n type = ' + Field.type )
}
</script>
<form id="someform">
<select id="sample" >
Whats your favorite coutry?<br>
<option value="US">USA</option>
<option value="CA">CANADA</option>
<option value="MX">MEXICO</option>
</select>
<input type="button" onClick="alertselected()" value="alert" />
</form>
<p><img src="http://www.webune.com/images/headers/default_logo.jpg" /></p>
<p>Script Created by www.<a href="http://www.webune.com">Webune.com</a></p>
2. save the file as form-select.html and then open it with your browser to see it in action or you can download the complete code in the attachment on this topic
demo:
hope that helps
form-select.html