1. How to dynamically modify the default selection for a drop-down list
Two methods, the first embedded Java code: The principle is to first get the need to select the item, and then control in the Java code that tag needs to add selected, where wish is placed in the request of an object, that's all.
<SelectName= "Wish.visible"><%IntVisible=((Wish) Request.getattribute ("Wish"). getvisible ();%><OptionValue= "1"<%if (visible==1) {%>selected<%}%> > visible to Everyone</Option><OptionValue= "2"<%if (visible==2) {%>selected<%}%> > Visible to Friends </option> <option value= "3" <%if (Visible==3) {% >selected<%}< Span style= "color: #000000;" >%> > only visible to yourself </option > </select>
The second method is to use the JS solution: The principle is the page loading time to calculate which option is the default check
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en"><Html><Head><Title>untitled</Title><Script>functionPageinit () {VarStr="${sessionsocpe.inf}";VarObj=document.getElementById ("Sex");For(VarI=0; I<Obj.options.length;i++){If(Obj.options[i].text==STR) {obj.options[i].selected=True;Break; } } }</Script></Head><BodyOnLoad="Pageinit ()"><SelectName= "Sex"Id= "Sex"><OptionValue= "female"><a href = www.561.cn> female </a></option>< Option value> <a href = www.561.cn> male </a></ </option></ select></body></html< Span style= "color: #0000ff;" >>