Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear dropdown selection on radio button click

I have a set of radio buttons. When primary is selected, the Primary Company field is hidden. I would also like to at this time clear the drop down selection. How can I do this?

<p>
        <label>Company Type:</label>
        <label for="primary"><input onclick="javascript: $('#sec').hide('slow');" type="radio" runat="server" name="companyType" id="primary" checked />Primary</label>
        <label for="secondary"><input onclick="javascript: $('#sec').show('slow');" type="radio" runat="server" name="companyType" id="secondary" />Secondary</label>
        <div id="sec">
        <label for="primary_company">Primary Company:</label>
            <%= Html.DropDownList("primary_company", Model.SelectPrimaryCompanies, "** Select Primary Company **") %>
        </div>

    </p>
like image 402
RememberME Avatar asked Apr 21 '10 14:04

RememberME


1 Answers

You can clear the selection (that is, select the first option) like so:

$("#primary_company").find('option:first')
                     .attr('selected','selected');
like image 142
karim79 Avatar answered Sep 20 '22 07:09

karim79