473,396 Members | 1,804 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,396 software developers and data experts.

Using Javascript to select an entry in a drop down box

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
5 3950
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mark Constant | last post by:
I have a drop-down list now and I got it so when something is selected from the drop down list it calls a JavaScript function. I want it so the value selected from the drop-down list is sent as a...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
1
by: marc heiners | last post by:
Hello! I have to overgive an information from one website to another (same domain) by sertting a cookie with javascript. When the website is requested by a user a session cookie with a default...
1
by: scott | last post by:
Hello, Thanks in advance for any help you might be able to offer... I have an html table with two columns and 10 rows. The first column contains a textbox that is populated. The second column...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
4
by: phpmagesh | last post by:
Hi I am using php and smarty, what i have to do is i have a drop down box with dynamic name, id and values. like <select name="id" id="id" onchange="sample()" > {foreach key=key_data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.