Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2007, 01:45 AM
Authorized User
 
Join Date: May 2006
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to set a drop down option

hi i have created a drop down as below
Code:
<select name="test" onChange="Toggle(this)">
    <option value="one" SELECTED>one</option>
    <option value="two" >two</option>
    <option value="three" >three</option>
</select>
what happens is that onChange I do some check and based on this check I would like to show the user some other option, other than the one selected.
For example
if the user selects one i want to show in the drop down three
if the user selects two i want to show in the drop down one
if the user selects three i want to show in the drop down one

i use the statement

Code:
if(control.options[control.selectedIndex].value == 'three')
 control.options.value = 'one';
I have simillar checks for all conditions
This works in IE but not in firefox. so how do id solve this problem

many thanks in advance

 
Old July 30th, 2007, 01:07 AM
Authorized User
 
Join Date: Oct 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this one. I've checked it for Firefox.

<select name="test" id = 'test' onChange="Toggle()">
.................................................. ..
</select>


and use following function

function Toggle() {

if(document.getElementById('test').value == 'three')
 document.getElementById('test').value = 'one';

}
 
Old August 1st, 2007, 01:22 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I agree, getElementById is pretty well supported and should be more robust than control.options (at least I'm not familiar with it).

I'd make one small change. If user has javascript disabled, this could throw errors. That's a pretty common problem because Microsoft has pretty much thrown up its hands trying to provide javascript security. A lot of times IE ships with JS disabled by default. The function will be more stable if you make this statement the first line of the Toggle() function...

if (!document.getElementById) return;

That way if the browser doesn't respond to the getElementById request, the script terminates. The script won't run, but neither will it throw errors; it's a "progressive enhancement" technique.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old August 8th, 2007, 05:50 AM
Authorized User
 
Join Date: Oct 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

taking notice :)
Thanks

Best,
Anna





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath: set operation with a disjoint node set rich_unger XSLT 7 May 6th, 2008 09:24 AM
Create Check Boxes/Option buttons/Option Group hewstone999 Access VBA 1 March 14th, 2008 07:25 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
how i set charcter set to a connection yoord BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2005 07:47 AM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.