JSObtains the value and text of the selected item in the drop-down list.
JS provides two methods to get the value of the drop-down box and text online: But some people are very irresponsible, and they did not take into account the errors caused by the differences between browsers, as a result, many new users cannot find errors for a long time!
Below I will summarize the values and text of the selected items in the drop-down box in Firefox and IE:
1. Methods supported by IE and Firefox:
Get Text
VaROBJ = Document. getelementbyid ('select _ template ');
VaR text = obj. Options [obj. selectedindex]. Text; // get text
VaROBJ = Document. getelementbyid ("select_template ");
For(I = 0; I <obj. length; I ++) {// The length of the drop-down box is the number of options
If(OBJ [I]. Selected =True){
VaR text = OBJ [I]. Text; // get text
}
}
Compared with the previous method
2. ie does not support Firefox:
VaR OBJ = Document. getelementbyid (name );
For (I = 0; I <obj. length; I ++ ){
If (OBJ [I]. Selected = true ){
VaR text = OBJ [I]. innertext;
}
}
Methods for getting values IE and Firefox:
VaR value = Document. getelementbyid ("select_template"). value; // get the value
Conclusion: Both IE and Firefox support the value and text attributes. Firefox does not support the innertext attribute.
JS implements the current page to open a new link:
Window. Location. href = URL;