forms - Get value of selected option using jquery -
forms - Get value of selected option using jquery -
this question has reply here:
get selected value of dropdown's item using jquery 20 answersmy question may stupid, because new web development , confused now.
first part of question that, when print stuff using console.log(some element), gives me giant object listeners returns html string simply this:
<option value="cs 245">cs 245</option> the way found some element above using selector follows:
$( ".course_list option:selected" )[0] i sorry terminology here because want know difference between complex object , object above (also name of them). have tried best take words, fail create clearer due lack of experience. if understand mean please help me edit question , provide answers, in advance.
then sec part of question want "cs 245" string above object.i have tried
$( ".course_list option:selected" )[0].val(); $( ".course_list option:selected" )[0].attr("value"); $( ".course_list option:selected" )[0].text(); but of them give me error:
uncaught typeerror: undefined not function i have included jquery , there no other crash/file_not_found shown in console. using latest bootstrap , formstone selecter, not sure how affects me here.
can help?
you don't need convert javascript object raw dom element, this:
$( ".course_list option:selected" ).val() when $( ".course_list option:selected" )[0] getting raw dom element not jquery object phone call val() on give error.
with dom element can seek this:
$( ".course_list option:selected" )[0].getattribute("value") for more understanding can refer so post
jquery forms twitter-bootstrap-3
Comments
Post a Comment