[jQuery] Re: Forcing a select box to "select" a specified option

2007-05-30 Thread Andy Matthews

That did it Dan. Thanks!

-Original Message-
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Dan G. Switzer, II
Sent: Wednesday, May 30, 2007 8:56 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Forcing a select box to "select" a specified option


Andy,

>Hrm...
>
>That doesn't work. I think you might have misunderstood me though. I 
>want to force the selected attribute of the second option element.
>
>I tried this too:
>$('#RedMakeSelect:first-child option:nth- 
>child(1)').attr('selected','true');
>
>And that didn't work either.

I can't remember if the nth-child() starts at 0 or 1. If it starts at 1,
you'd need to use the value 2.

However, now that you've said you're just trying to select the second item,
I'd do what was previously suggested an go straight to the DOM:

$('#RedMakeSelect:first-child option")[1].selected = true;

-Dan




[jQuery] Re: Forcing a select box to "select" a specified option

2007-05-30 Thread Dan G. Switzer, II

Andy,

>Hrm...
>
>That doesn't work. I think you might have misunderstood me though. I want
>to
>force the selected attribute of the second option element.
>
>I tried this too:
>$('#RedMakeSelect:first-child option:nth-
>child(1)').attr('selected','true');
>
>And that didn't work either.

I can't remember if the nth-child() starts at 0 or 1. If it starts at 1,
you'd need to use the value 2.

However, now that you've said you're just trying to select the second item,
I'd do what was previously suggested an go straight to the DOM:

$('#RedMakeSelect:first-child option")[1].selected = true;

-Dan



[jQuery] Re: Forcing a select box to "select" a specified option

2007-05-30 Thread Andy Matthews

Hrm...

That doesn't work. I think you might have misunderstood me though. I want to
force the selected attribute of the second option element.

I tried this too:
$('#RedMakeSelect:first-child option:nth-child(1)').attr('selected','true');

And that didn't work either. 

-Original Message-
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Dan G. Switzer, II
Sent: Tuesday, May 29, 2007 5:54 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Forcing a select box to "select" a specified option


Andy,

>$('#RedMakeSelect:first-child [EMAIL PROTECTED]')

I believe IE always has the value attribute defined--even if it's not
defined in your markup (ie. it essentially adds a value="" to your tag.) If
you know the 2nd element should have a value attribute if it's present, then
I'd just do:

$('#RedMakeSelect:first-child option:nth-child(1)')

-Dan




[jQuery] Re: Forcing a select box to "select" a specified option

2007-05-29 Thread Dan G. Switzer, II

Andy,

>$('#RedMakeSelect:first-child [EMAIL PROTECTED]')

I believe IE always has the value attribute defined--even if it's not
defined in your markup (ie. it essentially adds a value="" to your tag.) If
you know the 2nd element should have a value attribute if it's present, then
I'd just do:

$('#RedMakeSelect:first-child option:nth-child(1)')

-Dan



[jQuery] Re: Forcing a select box to "select" a specified option

2007-05-29 Thread Jeffrey Kretz
I've done it this way:

 

$('#selectid')[0].options[1].selected = true;

 

JK

 

  _  

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Andy Matthews
Sent: Tuesday, May 29, 2007 2:46 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Forcing a select box to "select" a specified option

 

I'm doing a related select dropdown here (bottom middle of the page):

http://w3.normreeveshonda.com/pages/page.cfm?pageid=80976
 &pagetype=26&featureid=-1

 

In FF, under New vehicles, the Make dropdown defaults to HONDA as desired.
In IE though, it stays on "select a make". Here's the code that I'm passing
back to the page for that select box:

 

select a makeHONDA

 

Ideally, I'd just do this:

select a makeHONDA

 

but that doesn't work for some odd reason. So I'd like to default it to the
first dropdown that has a value attribute. How would I go about that?

 

$('#RedMakeSelect:first-child [EMAIL PROTECTED]')

 

or something like that?



 

Andy Matthews
Senior Coldfusion Developer

Office:  877.707.5467 x747
Direct:  615.627.9747
Fax:  615.467.6249

[EMAIL PROTECTED]
www.dealerskins.com  

 

<>