[Javascript] Pre-selecting a Select Box multiple items using a convenientfunction
Chris Tifer
christ at saeweb.com
Thu Jun 19 14:24:33 CDT 2003
Sure...
var objEl = document.forms['formName'].elements['dropdownName']
for(var x = 0; x , objEl.length; x++){
var strVal = objEl.options[x].value
if(strVal.indexOf(strMatchingCriteria) > 0){
objEl.options[x].selected = true
}
}
Something like that should work (I haven't tested for errors), but I'm not
so sure it's going to be able to select multiple matches if that's what
you're looking
for. In your case of expanding to radios, it wouldn't be possible anyway
as multiple radio buttons cannot be checked as long as they are part of a
group.
Now with checkboxes, that could definitely be done.
Hope that helps,
Chris Tifer
http://emailajoke.com
----- Original Message -----
From: "DEV" <dev at qroute.net>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, June 19, 2003 3:07 PM
Subject: [Javascript] Pre-selecting a Select Box multiple items using a
convenientfunction
> Is there nice javascript function outthere to go thru the options of a
> select box and setting those options to "SELECTED" where a match occurs ?
>
> Something like this
>
> function SetSelect (selObject,values)
> {
> /*
>
> assuming values are comma seperated, we can put "values" into an array
using
> split
>
> and then cycle thru the select options and see if any of the items in
> "values" has a one tp one match if so, we set the selObject's selected
>
> attribute on for that option
>
> Example if the select box is a US states select,
> a call like this <script>SetSelect
> (window.document.all.selStates,"California,New York")</script> should make
> the California and NewYork highlighted in the multiple select
>
> }
>
>
> Once I figure this out, I'd like to extend the same concept to radio optns
> and check boxes as well with similar functions.
> If you can kindly assist me on this, I's appreciate it.
>
> Regards,
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list