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>      <optionvalue= "3"<%if (Visible==3) {%>Selected<%}%>> Visible only 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">Woman</option><optionvalue= "Male">Man</option></Select></Body></HTML>

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.