Capture instance code of select combo Option

Source: Internet
Author: User

This is a registration form, requiring users to select "Professional staff" and "qualitative staff, display the corresponding forms of "visitors are available" and "industries that are easy to access" respectively. When the two boxes are unselected, they are also hidden.
HTML section

CopyCode The Code is as follows: <p>
<Label class = "title"> register for a part-time position (required) <br/> press Ctrl to select multiple positions. </label>
<Select onchange = "showeasyvisitbox (this)" size = "10" style = "width: 200px;" multiple = "multiple" id = "kc_selectjob" name = "kc_selectjob">
<Option selected = "selected" value = "entry clerk"> entry clerk </option>
<Option value = "street visitor"> street visitor </option>
<Option value = "street access Blocker"> street access blocker </option>
<Option value = "telemarketers"> telemarketers </option>
<Option value = "mystery customer"> mystery customer </option>
<Option value = "professional guest"> professional guest </option>
<Option value = "Enterprise visitors"> enterprise visitors </option>
<Option value = "qualitative liaison officer"> qualitative Liaison Officer </option>
<Option value = "host"> host </option>
<Option value = "quality controller"> quality controller </option>
<Option value = "Data Recorder"> data recorder </option>
</SELECT>
</P>
<P id = "supportvisitbox" style = "display: none;">
<Label class = "title"> the type of the respondent is provided. </label>
</P>
<P id = "easyvisitbox" style = "display: none;">
<Label class = "title"> industries that are easy to access </label>
</P>

Javascript Section

Option cannot define the event (I did not try it out), so the event must be defined on select. The onchange event is used here, And the onchange event is triggered when the object changes. Here, the onchange event is much more reasonable than the onclick event, and the effect is better.
When debugging this script, I first used selectedindex. The experiment found that selectedindex can only capture the first selected option when multiple options are selected. I checked the reference books and found that I had taken a detour.

Copy code The Code is as follows: var olistbox = Document. getelementbyid ("kc_selectjob ");

Olistbox. onchange = function showeasyvisitbox (){
VaR oeasyvisitbox = Document. getelementbyid ("easyvisitbox ");
VaR osupportvisitbox = Document. getelementbyid ("supportvisitbox ");
If (olistbox. Options [5]. Selected)
{
Oeasyvisitbox. style. Display = "Block ";
}
Else {
Oeasyvisitbox. style. Display = "NONE ";
}

If (olistbox. Options [7]. Selected)
{
Osuppvisvisitbox. style. Display = "Block ";
}
Else {
Osuppvisvisitbox. style. Display = "NONE ";
}

}

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.