How to pass <select> html data in bootstrap modal to jquery -


i'm trying figure out how pass selected value tag located in modal:

<div class='row'> <div class='col-md-8'> <form class='form-inline'> <select class='form-control' name='sel1' id='sel1'>       <option>1.00</option>       <option>1.25</option>       <option>1.50</option>       <option>1.75</option>       <option>2.00</option>       <option>2.25</option>       <option>2.50</option>       <option>2.75</option>       <option>3.00</option>       <option>5.00</option>       <option>inc</option>       <option>drp</option>       <option>wdrw</option> </select>  </div> <div class='col-md-4' align='right'> <input style='display: block; width: 100%;' type='button' class='btn btn-success' value='enter grade' onclick='entergrade($offeringno)'' /> </div> 

here jquery code:

function entergrade(offering) {   var enteredgrade = $("#mymodal3 #sel1").val();   var gradeoffering = offering;   alertify.confirm("enter grade?", function (e)   { if (e) {     $.ajax({         url : "action.php",         type : "post",         data : {             gradeofferingpost : gradeoffering,             enteredgrade1: enteredgrade         },         success : function(data) {           alertify.alert(data);           show_test();         }});       $('#mymodal3').modal('toggle');   } else {       txt = "you pressed cancel!";   } }); } 

what correct syntax selected option sel1 select (that inside modal) javascript function?

you trying access value of element not have value. looking .text(). if want selected text of option should replace this:

var enteredgrade = $("#mymodal3 #sel1").val(); 

with this:

var enteredgrade = $('#sel1 :selected').text(); 

if interested in .val() must replace

<option>1.00</option> <option>1.25</option> ... 

with this:

<option value="1.00">1.00</option> <option value="1.25">1.25</option> ... 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -