1. Text box
1.1 <input type= "text" name= "test" id= "Test" >
The value is assigned to the variable t by the Var T=document.getelementbyid ("Test").
1.2 You can, of course, assign the value of a given variable to a text box, for example:
var m = "5";
document.getElementById ("Test"). value= m;
2. Drop-down list box
2.1 <select name= "sel" id= "sel" "onchange=" Look (); " >
<option value= "1" >11</option>
<option value= "2" selected>22</option>
<option value= "3" >33</option>
</select>
with Var S=document.getelementbyid ("sel"). Value gets the value selected in <select> box, where the value= "2" option is selected by default, so the value assigned to the variable s is "2" instead of "22",
If you want to assign a "value" such as "3" ("33") to the Test text box selected in <select>, you can use the following method
<script language= "JavaScript" >
function Look () {
var se =document.getelementbyid ("sel");
var option=se.getelementsbytagname ("option");
var str = "";
for (Var i=0;i<option.length;++i)
{
if (option[i].selected)
{
document.getElementById ("Test"). Value = Option[i].text;
}
}
}
</script>
2.2 Compares the given value to the value in the <select> box, select it if <option> 's value in <select> is the same as the given value.
var m = "2",
for (var i = 0;i<document.getelementbyid ("sel"). length;i++)
{
With (document.getElementById ("sel"). Options[i])
{
if (value = = m)
{
selected = true;
}
}
}
3. Single selection box
The name attribute value must be the same for a row of a single marquee, so that the radio can be implemented.
<input type= "Radio" Name= "a" value= "1" >aaaaaaaaaa<br>
<input type= "Radio" Name= "a" value= "2" >bbbbbbbbb<br>
<input type= "button" onclick= "Check ();" value= "Test" >
<script language= "JavaScript" >
<!--
function Check ()
{
var sel = 0;
for (var i = 0; i < Document.getelementsbyname ("a"). Length; i++)
{
if (Document.getelementsbyname ("a") [i].checked)
{
sel = Document.getelementsbyname ("a") [I].value;
}
}
if (sel = 1)
{
Alert ("Aaaaaaaaaa");
}
else if (sel== 2)
{
Alert ("BBBBBBBBB");
}
}
-->
</script>
Turn from: http://www.cnblogs.com/maizitongxue/archive/2009/03/13/1410890.html