By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,948 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,948 IT Pros & Developers. It's quick & easy.

button selects an option

P: n/a
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').sele cted =
'appartamenti'" value="Appartamenti" class="button" />

That's the way to go?

thanks.

Oct 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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').sele cted =
'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);
}
---
HTH.
Oct 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.