Results 1 to 2 of 2

Thread: [RESOLVED] setting dropdownfor value client side.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Resolved [RESOLVED] setting dropdownfor value client side.

    Hi All,

    I have the following in one of my pages:
    Code:
    @Html.DropDownListFor(model => model.OccupationID, new SelectList(Model.Occupations, "Value", "Text"), "-- Select --", new { @class = "EnabledDropDownList400" })
    it renders and populates from the server no problem and it has valid values.

    Now rather than go all the way to the server, under 1 condition when the user selects a value from another dropdown I need to set a default value in the above dropdown. I can see that the value exists in my dropdown, but it just will not set.

    My JQuery Function to set the default is entered at the correct time.
    I have tried the following to NO avail:

    Code:
    $("#OccupationID option[text='Clerical and Managerial'] ").attr("selected",true);
    $("#OccupationID option[text='Clerical and Managerial'] ").attr("selected","selected");
    if I perform a view source on the page I have:
    Code:
    <select class="EnabledDropDownList400" data-val="true" data-val-number="The field Occupation must be a number." id="OccupationID" name="OccupationID"><option value="">-- Select --</option>
    <option value="8000000007540730">Abattoir</option>
    <option value="8000000007540734">Abrasive Wheel Manufacturers</option>
    <option value="8000000007540754">Advertising contractors i), i.e.boardings</option>
    <option value="8000000007540758">Advertising handbill ii)distribution only</option>
    <option value="8000000007540762">Advertising ii) agencies</option>
    <option value="8000000007540766">Aerated Water and Soft Drinks</option>
    <option value="8000000007541219">Clerical and Managerial</option>......

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: setting dropdownfor value client side.

    ok guys found it:

    Code:
    $("#OccupationID").val($("#OccupationID option:contains('Clerical and Managerial')").val());

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width