Home > Article > Web Front-end > Simple example of JS getting the value of text box, drop-down box and radio button_javascript skills
1. Text box
1.1
Assign the value to variable t through var t=document.getElementById("test").value,
1.2 Of course, you can also assign known variable values to the text box in reverse, for example:
var m = "5";
document.getElementById("test").value= m;
2. Drop-down list box
2.1
Get the value selected in the
If you want to assign the "value" selected in
2.2 Compare the given value with the value in the
Copy code
The code is as follows:
Get the value and text of the selected item in the drop-down box under Firefox and IE:
1. Methods supported by both IE and Firefox:
Get text
var obj=document.getElementById("select_template");
for(i=0;i if(obj[i].selected==true) { var text=obj[i].text;//Get text }
}
1. IE supports Firefox but not:
for(i=0;i
var text= obj[i].innerText;
}
}
Summary: In fact, the main reason is that both IE and Firefox support the value and text attributes, but Firefox does not support the innerText attribute.
Js implements opening a new link on the current page:
window.location.href=url;