Solution for receiving background return values in select, return values in select background

Source: Internet
Author: User

Solution for receiving background return values in select, return values in select background

When performing page form or conditional filtering, how to refresh the select tag value and keep the selected value after refreshing the page. The following two solutions are provided:

Premise: the front-end select label name is type; the backend receives the type value, and returns the type value to the page after the business is completed.

1. assign values to select tags using jquery. 

Step 1: add an id for select to facilitate jquery control.

<Select name = "type" id = "type"> <option value = "0"> excellent </option> <option value = "1"> good </option> <option value = "2"> pass </option> </select>

Step 2: Use jquery to receive background type values and assign values to select tags.

<Script type = "text/javascript"> $ (function () {$ ("[name = 'type']"). val ($ {type}) ;}) </script>

Or
<script type="text/javascript">   $(function(){      $("#type").val(${type});   })</script>

Ii. Use jstl to control whether the select option is selected.

<Select name = "type"> <option value = "0" <c: if test = "$ {type = 0}"> selected </c: if >>> excellent </option> <option value = "1" <c: if test = "$ {type = 1}"> selected </c: if> good </option> <option value = "2" <c: if test = "$ {type = 2}"> selected </c: if> pass </option> </select>

 

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.