Ricardo,
I am a bit new at using jQuery so this could be an inane question:
Is the 'select' applied at the selector?  If my control's id is
emplist would the correct syntax be:

$('#emplist select').val(empSelected);

empSelected, in this case, is a variable containing the value I want
to set the 'selected' attribute for.

This page is a template rendered by a server call and the server sets
the value of each of the fields of the form.  But I want each field to
have the values that can be selected.  The complete code is:

// Load the list using Ajax and Json:
        $('#emplist').loadList(getEmpListURL, '#emplist');
// Then set the value of the selected option
        $('#emplist select').val(empSelected);
The list is populated but the option value is not set to 'selected'



On Sep 29, 5:27 pm, ricardobeat <[EMAIL PROTECTED]> wrote:
> $('select').val('value') should work (it needs to be applied to the
> <select>, not the <option>
>
> - ricardo
>
> On Sep 29, 6:55 pm, Pete <[EMAIL PROTECTED]> wrote:
>
> > I have an element that I populate with an Ajax call and returns a list
> > of items for a combo box. In some cases the page containing the
> > element gets loaded with existing values and rendered and I'd like the
> > textbox to contain an item that was selected before the element is
> > rendered.
>
> > Is there a way to set that value?  I have done some searching but
> > haven't found a solution as yet.  I have looked at setting the
> > "selected" attribute but haven't found an example that works.  I have
> > also tried setting the selected value with .val(myValue); but, again,
> > tried it and didn't get it to work.
>
> > It should be simple.  But I can't seem to crack it.  Suggestions?
>
> > Thanks,
>
> > Pete

Reply via email to