开发者

jQuery resetting value of form input when hidden

开发者 https://www.devze.com 2022-12-27 11:28 出处:网络
I am trying to clear the value attribute of an \'Other\' form input when it is hidden from the user like so:

I am trying to clear the value attribute of an 'Other' form input when it is hidden from the user like so:

// hide 'Other' inputs to start
$('.jOther').hide();

// event listener on all select drop downs with class of jTitle 
$("select.jTitle").change(function(){

    //set the select value
    var $titleVal = $(this).val();

    if($titleVal != 'Other') {
        $(this).parent().find('.jOther').hide();
        $(this).parent().find('input.jOther').attr("value", "");
    } else {
        $(this).parent().find('.jOther').show();
    }

    // Sets a cookie with named after the title field's ID attribute        
    var $titleId = $(this).attr('id');

    $.cookies.set('cpqb' + $titleId, $titleVal);

});

It doesn't seem t开发者_Python百科o be working and i have tried the following to no avail as well:

$(this).parent().find('input.jOther').val("");

I have managed to alter other attributes in this way, such as the name, maxlength etc.

Any ideas?


As an alternative, you can clear it's value before hiding or soon after showing. Or try this:

$('input.jOther:hidden').val('');
0

精彩评论

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

关注公众号