views:

36

answers:

1

Hi,

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 to 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?

+1  A: 

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

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