473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Selecting items in a listbox

Hi - is it possible to pass a comma delimeted list to a javascript
function, which will then loop through the list, and check against a
listboxs items, and if the value in the list, corresponds to an item in
the listbox, the listbox item should be 'selected' - I'd like this to
happen for a multiple select list box.

Something along the lines of (sorry, I'm not knowledgable in JS just
yet, but need to solve the problem):

function selItems()
{
selItemsInList('1,4,4,7,8');
}

selItemsInList(str)
{
for each checkitem in str
{
for each item in selectlist
{
if item.value == checkitem.value
{
selectlist.item.checked;
}
}
}

Thanks for any help,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
5 2309
Hi - I've managed to get this working to an extent - I'm just not sure
how to get a comma delimmetted list, and iterate through that - here's
what I have so far, taking info from hard coded variables:

function pop(inForm)
{
var option0 = "1" //this is the part I want to be read from a comma
list
var option1 = "6"
var option2 = "3"
for (var i=0; i < 3; i++) {
for (var x=0; x < 3; x++)
{
if (inForm.lbMT.options[i].value==eval("option" + x))
{
alert("equal so selecting");
inForm.lbMT.options[i].selected=true;
}
}
}
}


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #2
"Mark" <an*******@devdex.com> wrote:
Hi - is it possible to pass a comma delimeted list to a javascript
function, which will then loop through the list, and check against a
listboxs items, and if the value in the list, corresponds to an item in
the listbox, the listbox item should be 'selected'


You can use my general setInputValue() function on multiple select boxes,
like this:
setInputValue(document.forms[0].mySelect,"a,d,h");

The function, along with others, can be found in my validations lib at:
http://www.mattkruse.com/javascript/validations/

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 23 '05 #3
In article <40*********************@news.frii.net>, Mark
<an*******@devdex.com> wrote:
Hi - I've managed to get this working to an extent - I'm just not sure
how to get a comma delimmetted list, and iterate through that - here's
what I have so far, taking info from hard coded variables:

function pop(inForm)
{
var option0 = "1" //this is the part I want to be read from a comma
list
var option1 = "6"
var option2 = "3"
for (var i=0; i < 3; i++) {
for (var x=0; x < 3; x++)
{
if (inForm.lbMT.options[i].value==eval("option" + x))
{
alert("equal so selecting");
inForm.lbMT.options[i].selected=true;
}

Set an array like this:

var optionList = ["a","b","c", etc];
for (x=0;x<optionList.length;x++) {
if (optionList[x] == ???) dothis
};

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #4
Hi Matt - thank you for this.

I tried the setInputValue on your site, and entered 1,3 and "1,3" - but
only one of the select items hilited - have I entered the numbers
incorrectly?

Thanks again for the help,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
Sorted - thanks for the help:

<script language="JavaScript">
function pop()
{
var optionList = arguments;
var ddl=document.getElementById("lbMT");
for (var i=0; i < 3; i++) {
for (var x=1;x<optionList.length;x++)
{
if (ddl.options[i].value==optionList[x])
{
ddl.options[i].selected=true;
}
}
}
}

</script>
</head>
<body>
<form>
<select name="lbMT" id="lbMT" size="10" multiple>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<INPUT TYPE="button" VALUE="Populate Select List"
onClick='pop(this.form, 19,20,1,3,3,0)'>
</form>
</body>


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
1
by: Bob Geltz | last post by:
I am able to populate a ListView with several detail lines (several columns). When finished, I would like to pre-select the first item in the list (before the user interacts with the list). This...
4
by: Paddy | last post by:
How do I select a subitem from a listview after clicking on the first column? Couldn't find it in MSDN. Thank you. Paddy.
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
4
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you...
3
by: Jonesgj | last post by:
Chaps, How would I select all items in a listbox using code? I'm sure its an easy one but .... Thanks
4
by: John | last post by:
Hi there, I'm just starting at VB.NET (all VB come to that), and have what's probably a very basic question: I have a form in Visual Studio 2003 that has a listbox that is meant to be...
2
by: miller504 | last post by:
I'm trying to select several items from a listbox. My code is working except when the form loads the first time. I have the code to select the items inside sub Initialize_CbLeague. If I call sub...
4
by: Duncan Smith | last post by:
So far, the quikest way I have found to select all items in a list box is to turn off updates, set a wait cusror and then call SetSelected on each item (see below), but it's too slow when the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.