jQuery resetting value of form input when hidden
Posted
by RyanP13
on Stack Overflow
See other posts from Stack Overflow
or by RyanP13
Published on 2010-04-21T11:12:33Z
Indexed on
2010/04/21
11:23 UTC
Read the original article
Hit count: 255
jQuery
|JavaScript
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?
© Stack Overflow or respective owner