Use js to get the value selected in the drop-down box

Source: Internet
Author: User
This article describes how to use js to get the selected value from the drop-down box. The instance code is attached. If you need a friend, you can refer to the current requirements: in the drop-down box, if you want to select a franchisee to continue to select a school, if you select a platform administrator, you do not need to select a school. Hide the selected drop-down list.

Select the enumerated value:

////// Platform role ///Public enum AdministratorRole {[Display (Name = "platform administrator")] PlatformAdministrator = 1, [Display (Name = "franchisee")] JoiningTrader = 10}

Code:

@Html.LabelFor(x => x.AdministratorRole, new { @class = "col-sm-2 control-label" })

@Html.EnumDropDownListFor(x => x.AdministratorRole, new { @class = "form-control", onChange = "showSchool(this.value)", placeholder = Html.DisplayNameFor(x => x.AdministratorRole) })

@Html.ValidationMessageFor(x => x.AdministratorRole)

@Html.LabelFor(x => x.SchoolId, new { @class = "col-sm-2 control-label" })

@Html.DropDownListFor(x => x.SchoolId, Model.Schools, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.SchoolId) })

@Html.ValidationMessageFor(x => x.SchoolId)

Hide the school list first. style = "display: none" has the same effect. We use the onChange event in the drop-down box to execute the Set Method showSchool (). The parameter here is the value we selected, and this represents the AdministratorRole.

Js Code:

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.