Selection of trigger events and extended _javascript techniques for select dropdown box in bootstrap

Source: Internet
Author: User

Select the dropdown box, and when you select an option, the foreground displays a change, and you know which options are selected.

This is a good solution:

As follows:

<div class= "Page-header" >
<div class= "Form-horizontal" >
<div class= "Control-label col-lg-0" >
</div>
<div class= "col-lg-2" >
<select class= "Form-control" onchange= " Selectonchang (This) ">
<option> All applications for business </option> <option> to be
audited merchant </option>
<option> failed to approve merchant </option>
<option> approved merchant </option>
</select>
</ Div>
</div>

Js:

function Selectonchang (obj) { 
//Get the selected option label option 
alert (obj.selectedindex);
}

The onchange and SelectedIndex are used here.

The onchange event occurs when the contents of the domain change.
The onchange event can also be used for events that are triggered when a radio box and a check box change.

SelectedIndex: Sets or returns the index number of the selected item in the Drop-down list.

This will trigger a change when we change the option.

Effect as shown:

In doing so, we can only get the selected item, and if we select which item, we need to pass special information, what should we do at this time?

<div class= "Page-header" >
<div class= "Form-horizontal" >
<div class= "Control-label col-lg-0" >
</div>
<div class= "col-lg-2" >
<select class= "Form-control" onchange= " Selectonchang (This) ">
<option value= ' All ' > All applications for Business </option>
<option value=" check_pending "> to be audited merchant </option>
<option value=" No "> failed to approve merchant </option>
<option value=" yes "> Approved merchant </option>
</select>
</div>
</div>

In other words, I want to get that value when I select it, and how to do it at this time.

There is only one way to do this, and there should be plenty of other ways.

function Selectonchang (obj) { 
var value = Obj.options[obj.selectedindex].value;
alert (value);
}

The effect chart is as follows:

The above is a small set to introduce the bootstrap about select Drop-down box to select trigger events and expansion, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.