button selects an option

K

kain

hi,
I've a button, onclick I need to automagically select an option a in
dropdown box.
something like:

<input type="button"
onclick="document.getElementById('tematismo').selected =
'appartamenti'" value="Appartamenti" class="button" />

That's the way to go?

thanks.
 
E

Elegie

kain wrote:

Hi,
I've a button, onclick I need to automagically select an option a in
dropdown box.
something like:

<input type="button"
onclick="document.getElementById('tematismo').selected =
'appartamenti'" value="Appartamenti" class="button" />

Provided your SELECT element has a NAME attribute called "tematismo":
just put the following in your ONCLICK attribute:

---
selectOptionsByValue(this.form.elements['tematismo'],this.value)
---

....defining the javascript function as:

---
function selectOptionsByValue(o, v) {
v=v.toLowerCase();
for(var opt=o.options, ii=opt.length; ii--;)
opt[ii].selected=(opt[ii].value.toLowerCase()==v);
}
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top