This example describes the method for the currently selected value of the JS settings drop-down list box. Share to everyone for your reference, specific as follows:
1. JS Code:
function Setselectoption (ObjID, targetvalue) {
//objid: Id;targetvalue of drop-down list box: Currently selected value
var obj = document.getElementById (ObjID);
if (obj) {
var options = obj.options;
if (options) {
var len = options.length;
for (Var i=0;i<len;i++) {
if (Options[i].value = = targetvalue) {
options[i].defaultselected = true;
Options[i].selected = true;
return true;
}
}
else {
alert (' missing element (s)! ');
}
} else {
alert (' missing element (s)! ')
;}
2. Set the current selection of a Drop-down list box in a JSP
<select>
<option value= "1" <%if (sesssionvalue==1) {%> selected= "selected" <%}%>>1:b < /option>
<option value= "2" <%if (sesssionvalue==2) {%> selected= "selected" <%}%>>2:b </ option>
<option value= "3" <%if (sesssionvalue==3) {%> selected= "selected" <%}%>>3:c </ option>
<option value= "4" <%if (sesssionvalue==4) {%> selected= "selected" <%}%>>4:d </ Option>
</select>
I hope this article will help you with JavaScript programming.