开发者

jQuery HTML select toggle/show/hide

开发者 https://www.devze.com 2022-12-18 13:46 出处:网络
I need to hide an \'Other\' label and corresponding input field as default.Then when a user selects \'Other开发者_开发百科\' from a HTML select drop down the matching label and text input need to show

I need to hide an 'Other' label and corresponding input field as default. Then when a user selects 'Other开发者_开发百科' from a HTML select drop down the matching label and text input need to show. If they navigate to a different option then the label and text input are hidden again:

HTML:

    <select id="indTitle" class="inlineSpace">
        <option value="Please select">Please select...</option>
        <option value="Mr">Mr</option>
        <option value="Mrs">Mrs</option>
        <option value="Ms">Ms</option>
        <option value="Miss">Miss</option>
        <option value="Dr">Dr</option>
        <option value="Other">Other</option>
    </select>
    <label for="indOther" class="inlineSpace">Other</label>
    <input type="text" class="text" name="indOther" id="indOther" maxlength="20" />


$('#indTitle').change(function() {
    if($(this).val() == 'Other') {
        $('label[for=indOther], #indOther').show();
    } else {
        $('label[for=indOther], #indOther').hide();
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号