I have function in which I create a div containing an onclick function, where I pass 2 variables. One is an int and the another one is a string. It’s accepting the int and not the string.
var html ="";
var intC = 0;
var flightBI="";
var mileage=0;
flightBI = $(this).find("FLIGHT").text();
fnCreateDiv(){
html+="<div class='ui-grid-a' id='Details" + intC +"' onclick='fnConfirm("+intC+","+mileage+");' >";
html+="</div>"
}
fnConfirm(intc,mileage){
alert(intc);
alert(mileage);
}
I am getting an alert for both intc and mileage, since both are integers. If in the same case I pass the flight, I am not getting a value. This is what we usually do with JavaScript but is it different in jQuery?
intC and mileage are both initialized to 0 (int) so they both alert the same value.
See this jsFiddle with the fix