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

Using Javascript to select an entry in a drop down box

P: n/a
Hi

I have a dropdown box containing about 10 values.

I would like to create a separate href on my page that when clicked will
make the drop down box go to a specific value. I do not want to have to
refresh the page to do this. Is it possible to have that sort of control
over a drop down box. ?

Andy
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
In article <Po*******************@fe2.news.blueyonder.co.uk >,
no_email@no_email.com enlightened us with...
Hi

I have a dropdown box containing about 10 values.

I would like to create a separate href on my page that when clicked will
make the drop down box go to a specific value. I do not want to have to
refresh the page to do this. Is it possible to have that sort of control
over a drop down box. ?


Yes, but using an href would be a bad idea for an internet application. I'd
use a button, myself, styled to look like a text link if such was the
requirement.

If you decide to use an anchor, it would be
<a href="someNoJSPage.html" onClick="choose();return false;">link</a>

function choose()
{
// change the names and selectedIndex appropriately
// both versions supplied for cross-browser
document.forms["myformname"].elements["myselect"].selectedIndex = 2;
document.forms["myformname"].elements["myselect"].options[2].selected =
true;
}

You can change that to accept a number param or whatever.

--
--
~kaeli~
Join the Army, meet interesting people, kill them.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
kaeli wrote:
Yes, but using an href would be a bad idea for an internet
application.


Not necessarily. You could use javascript to document.write the <a>, since
the link would only be relevant if js was enabled. Then you wouldn't need to
worry about onclick not firing.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #3

P: n/a
In article <ch*********@news1.newsguy.com>, ne********@mattkruse.com
enlightened us with...
kaeli wrote:
Yes, but using an href would be a bad idea for an internet
application.


Not necessarily. You could use javascript to document.write the <a>, since
the link would only be relevant if js was enabled. Then you wouldn't need to
worry about onclick not firing.


Yes, but then people without script couldn't use the page. Which, IMNSHO, is
a bad thing for many reasons.

--
--
~kaeli~
Why did kamikaze pilots wear helmets?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

P: n/a
kaeli wrote:
Yes, but using an href would be a bad idea for an internet
application.

Not necessarily. You could use javascript to document.write the <a>,
since the link would only be relevant if js was enabled. Then you
wouldn't need to worry about onclick not firing.

Yes, but then people without script couldn't use the page. Which,
IMNSHO, is a bad thing for many reasons.


That's not true - they could still use the page just fine. They just
couldn't trigger the functionality of selecting a certain value in the
select list. Since this functionality requires javascript, it makes sense to
only write the control if it can be used.

This is a better approach than pointing the href to
"javascript_required_notice.html" or something, if there's a way to hide the
link entirely if it will serve the user no purpose.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #5

P: n/a
In article <ch*********@news1.newsguy.com>, ne********@mattkruse.com
enlightened us with...
kaeli wrote:
Yes, but using an href would be a bad idea for an internet
application.
Not necessarily. You could use javascript to document.write the <a>,
since the link would only be relevant if js was enabled. Then you
wouldn't need to worry about onclick not firing.

Yes, but then people without script couldn't use the page. Which,
IMNSHO, is a bad thing for many reasons.


That's not true - they could still use the page just fine. They just
couldn't trigger the functionality of selecting a certain value in the
select list.

See, to me, that means they can't use the page. They can SEE it. They can't
USE it, since part of it is then broken.

Since I don't know what the page actually IS or what it is meant to do, the
fact that a control is broken may or may not break the entire thing. But at
least part of it doesn't work the same for people with no script as it does
for people with it - therefore, it is not fully functional (usable) for non-
JS users.
For all I know, it's actually a personal page or an intranet page and
everyone has script and it's a moot point. The OP didn't say.

*shrugs*

--
--
~kaeli~
Is it true that cannibals don't eat clowns because they
taste funny?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.