I use this function to set the <option> of a drop down input. Works in IE6
and FF that I know of. You'll notice it only works well for <option>s with
unique values. You could probably easily change it if you needed otherwise.

// Usage
$("[EMAIL PROTECTED]'State']").option( "CA" );

// "Plugin"
jQuery.fn.option = function (value) {
        return this.each(function() {
                var select = $(this)[0];
                for ( var i=0; i<select.length; i++ )
                        if (select[i].value == value)
                                select.selectedIndex = i;
        });
};


Kawika



dizzledorf wrote:
> 
> Seems like a simple action, and it works in Firefox, but not IE...
> 
> I'm trying to change the value of a dropdown box based on an event
> triggered in another text box.  It's a contact form, and I just want to
> change the state dropdown Select on the keyup of the 5th character of the
> zip input box.
> 
> re:
> $("#zip").keyup(function(){
>       if ($("#zip").val().length == 5) {
>               // IE can get in here, but doesn't execute the following line
>               $("#state").attr("value","FL");  // just testing for now
>       }
> });
> 
> As I mentioned, this works in Firefox 1.5.0.7, but not in IE6...
> 
> How do I get this going in IE?
> 
> Thanks!
> --DIZZLE
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-change-value-of-select-dropdown--tf2308098.html#a6420831
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to