HTML Technology Basics

Source: Internet
Author: User

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;" >>                 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.