So here is my code. I am trying to set the value of a hidden form input.
if($gender == "BOY" || $gender == "MALE" || $gender == "M" || $gender == "1") {
console.log('Its a boy!');
$(".girlsonly").hide();
document.getElementsByName('dressjacket')[0].placeholder='Jacket';
$('#majorgender').val('1');
};
if($gender == "GIRL" || $gender == "FEMALE" || $gender == "F" || $gender == "0") {
console.log('Its a girl!');
document.getElementsByName('dressjacket')[0].placeholder='Dress';
$('#majorgender').val('0');
};
Here is the form input:
<input type="hidden" name="majorgender" id="majorgender"></input>
It successfully logs "Its a girl!" or "Its a boy!" but afterwards when I insert "alert($('majorgender').val());
" it alerts "undefined"
If I log alert($('majorgender'))
it replies with "object Object" so I know it exists, I just dont know why its not setting properly.
Any thoughts?
alert($('foobarBARBAR'))
alertsobject Object
too, and obviously it doesn't exist. To test for existence, test the length property of the jquery object.alert($('foobarBARBAR').length)
alert($('majorgender').val())
or analert($('#majorgender').val())
?