Why isnt jQuery setting my value? -


so here code. trying set value of hidden form input.

if($gender == "boy" || $gender == "male" || $gender == "m" || $gender == "1") {         console.log('its boy!');         $(".girlsonly").hide();         document.getelementsbyname('dressjacket')[0].placeholder='jacket';         $('#majorgender').val('1');     };     if($gender == "girl" || $gender == "female" || $gender == "f" || $gender == "0") {         console.log('its girl!');         document.getelementsbyname('dressjacket')[0].placeholder='dress';         $('#majorgender').val('0');     }; 

here form input:

<input type="hidden" name="majorgender" id="majorgender"></input> 

it logs "its girl!" or "its boy!" afterwards when insert "alert($('majorgender').val());" alerts "undefined"

if log alert($('majorgender')) replies "object object" know exists, dont know why not setting properly.

any thoughts?

you alerting input majorgender $('majorgender').val() when need alert $('#majorgender').val()

because selecting input id must precede selector name hash #

and note jquery define every selector if not valid object not necessary if log show object means selector correct , exists :)

try , tell me if helpful :)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -