I am designing select types and check boxes with above code, now i want to get value of each select type and add them and show result in text box.
success: function(data) {
//console.log(data.students);
var student = "";
$.each(data.students, function(key, value) {
student += value +'<input type="checkbox" name="' + value + '" value="' + key + '">Months <select name="amount" class="month" onChange="add();"><option value="">Select months</option><option value="1">1</option><option value="3">3</option><option value="6">6</option><option value="12">12</option></select>';
});
student += 'Total Amount <input type="text" value"" id="total">';
student += '<button type="submit" > Pay</button>';
$('#hide').hide();
$('#student-list').show().html(student);
},
and my rest code
function add(){
//var value = ($(this).find("option:selected").text());
// var value= $("option:selected" ).text();
// var value= $(".option :selected").val();
var value= $(".month :selected").val();
sum(value);
//var val =$(this).val();
//alert(value);
}
function sum(value){
var total=0;
total=value*1000;
alert(total);
//$('#total').val(total);
}
not sure if this will work but try
$(".month option:selected").each(function(){
console.log($(this).val())
});
why not pass this ?
onChange="add(this);"
function add(this){
var value = this.value;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.