Selecting items in a list/menu with javascript

B

Brian

How can I use javascript to select Items in a List/Menu? For example:
(value1, value2) will select value1 and value2 in a list menu....
 
J

Joshie Surber

How can I use javascript to select Items in a List/Menu? For example:
(value1, value2) will select value1 and value2 in a list menu....

Can you clarify and include some sample code? We may be able to help if
we could better understand the problem.
 
B

Brian Ciarcia

OK.. I'll do my best to clarify. A user does a search and pulls up a
list of clients. I have a form on the side of the list that they can
use to add a new client if its not in the list. If the client is in the
list, they can click on the client's name and it will poplulate that
form with all of their information so they can update the record. One
of the fields is a List/Menu box that allow for multiple selections. So,
I am passing, for example onclick=popform('Show, Sold') which are two
elements in that menu box. I need to have both of those selected when I
do the onclick event. Is that possible?

Does that help?
 
J

Joshie Surber

If I am understanding right, you are trying to populate a couple of
text fields from the selection in a <select> tag selection?

<option value="textfield1|textfield2" onclick="popform(this)">some
option</option>

function popform(el) {
fields = el.value.split('|');
this.form.textfield1.value = fields[0];
this.form.textfield2.value = fields[1];
}

Is this something like what you were hoping for?
 
J

Joshie Surber

Never mind, I just figured out what you want.

el = document.formName.selectName;
opts = el.options;
for (i=0;i<opts.length;i++) {
if (opts.selected) {
// do something with this option
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top