How to change the options in the HTML drop-down box

Source: Internet
Author: User

After the form is submitted, the returned HTML page is re-rendered. The value and selectedIndex attributes of the SELECT control cannot keep the drop-down box in the status before the form is submitted. [Html] <SELECT id = "idState" style = "width: 150" name = "state" selectedIndex = "$! {State} "> <OPTION value =" "> all </OPTION> <OPTION value =" 1 "> pass </OPTION> <OPTION value =" 2 "> </OPTION> <OPTION value = "3"> pending </OPTION> </SELECT> <SELECT id = "idState" style = "width: 150 "name =" state "selectedIndex =" $! {State} "> <OPTION value =" "> all </OPTION> <OPTION value =" 1 "> pass </OPTION> <OPTION value =" 2 "> </OPTION> <OPTION value = "3"> pending </OPTION> </SELECT> a temporary solution is to add a script at the end of the vm file to assign a value to the drop-down box: [html] <script> $ ('# idstate '). val ('$! {State} '); </script> <script >$ (' # idstate'). val ('$! {State} '); </script> Another solution is to set the default selected item: [html] <SELECT id = "idState" style = "width: 150 "name =" state "value =" $! {State} "> <OPTION value =" "> all </OPTION> <OPTION value =" 1 "> end through </OPTION> <OPTION value =" 2 "SELECTED> </OPTION> <OPTION value = "3"> to be processed </OPTION> </SELECT> <SELECT id = "idState" style = "width: 150 "name =" state "value =" $! {State} "> <OPTION value =" "> all </OPTION> <OPTION value =" 1 "> end through </OPTION> <OPTION value =" 2 "SELECTED> </OPTION> <OPTION value = "3"> to be processed </OPTION> </SELECT> is written as follows: [html] <SELECT id = "idState" style = "width: 150" name = "state" value = "$! {State} "> <OPTION value =" "> all </OPTION> <OPTION # if ($! {State} = 1) SELECTED # end value = "1"> pass </OPTION> <OPTION # if ($! {State }== 2) SELECTED # end value = "2"> last pass </OPTION> <OPTION # if ($! {State }== 3) SELECTED # end value = "3"> pending </OPTION> </SELECT> <SELECT id = "idState" style = "width: 150 "name =" state "value =" $! {State} "> <OPTION value =" "> all </OPTION> <OPTION # if ($! {State} = 1) SELECTED # end value = "1"> pass </OPTION> <OPTION # if ($! {State }== 2) SELECTED # end value = "2"> last pass </OPTION> <OPTION # if ($! {State }== 3) SELECTED # end value = "3"> to be processed </OPTION> </SELECT> Note: During = comparison, velocity is used to differentiate data types. If you use strings "1", "2", and "3", the system always returns false. Reference: comparison issues in velocity http://www.oschina.net/question/237818_38403?sort=time&p=1 [Html] <PRE class = html name = "code"> <SPAN style = "FONT-FAMILY: Arial, Helvetica, sans-serif "> <SPAN style =" WHITE-SPACE: normal "> </SPAN> </PRE>

Related Article

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.