Search for Select Content in JS and select multiple

Source: Internet
Author: User

The company has a set of systems, and the Select menu stores too many categories. It is very difficult to find a category each time and a search is made.
I wrote comments for your reference.

form id =" form1 " name =" form1 " method =" Post " action =" ">

select name =" select " size =" 20 " id =" myselect " multiple =" multiple ">

Option value =" 11 "> 111444 Option >

Option value =" 22 "> 211144 Option >

Option value =" 33 "> 311155 Option >

Option value =" 44 "> 422355 Option >

<Option Value= "55">533333</Option>

</Select>

input name =" keywords " type =" text " id =" keywords ">

input type =" button " name =" button " id =" button " value =" Search for him " onclick =" selectone (document. getelementbyid ('keyword '). value) ">

</Form>

script language =" JavaScript ">

//ParametersKeywords ---InputKeywordSelectindex ---SpecifySelectIndex value of the Set

FunctionSelectone (keywords, selectindex)

{

KEYWORDS = keywords. Replace (// G,"")//Remove Spaces

var myselect = document. getelementbyid ( "myselect" ) // get the select Object

var J = 0; // Data Statistics

For(I = 0; I <myselect. length; I ++)//LoopOption

{

If(Myselect. Options [I]. Text. indexof (keywords )! =-1)//JudgmentOptionOfTextInclude or notKeyword

{

Myselect. Options [I]. Selected =True;//Selected

J ++;//Statistics

}

Else

{

Myselect. Options [I]. Selected =False;//Does not containKeywordsUnselect,If this clause is not added, it will be selected again

}

}

alert (" found " + J + " item " )

}

</Script>

 

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.