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 ";
}
}