Reputation: 469
var air = ITC.ITC.hotel.options.option[itc].packages.package[i].airfare - 1;
var opt = ITC.ITC.hotel.options.option[itc].packages.package[i].option - 1;
console.log((air+1)); // Display 1 in console
console.log((opt+1)); // Display 7 inconsole
detailHtml += '<button class="btn btn-primary btn-lg nav-book" type="button" onclick="book_package(\''+ITC.sid+'\' , '+ITC.ITC.hotel.orig_hot_num_xsl+' , \''+(itc+1)+'\' , '+(package_idx+1)+' , '+(air+1)+' , '+(opt+1)+');">'+lang['book']+'</button>';
When I do inspect element, the two last parameters of the function book_package are integer of 01 and 61 but when I do air+1 and opt+1 in the console I get 1 and 7 ...
<button class="btn btn-primary btn-lg nav-book" type="button" onclick="book_package('3dd57f6c9e133553378e11d7521ab1be1463751663', 1, '1,3', 7, 01, 61);">Book Now</button>
EDIT 2
I also tried
var air = parseInt(ITC.ITC.hotel.options.option[itc].packages.package[i].airfare) - 1;
var opt = parseInt(ITC.ITC.hotel.options.option[itc].packages.package[i].option) - 1;
'+(parseInt(air+1))+' , '+(parseInt(opt+1))+'
I cleared my browser cache, just incase, I still get the same issue
EDIT 3
New try, still the same issue ...
'+(1 + parseInt(air , 10))+' , '+(1 + parseInt(opt , 10))+'
Upvotes: 2
Views: 205
Reputation: 1028
Double check your data types for air and opt.
Check this out and see how the first alert has air as a number and the second one has it as string: plnkr.co/edit/4Ll6juBC3BEu1MgdUhjx?p=preview
Upvotes: 0
Reputation: 12161
At detailHtml += '<button...
you are starting with a string ... that makes JS interpret everything as a string concatenation, while at the other pieces of the code you don't have any strings to mess things up!
Solution:
detailHtml += '<button class="btn btn-primary btn-lg nav-book" type="button" onclick="book_package(\''+ITC.sid+'\' , '+ITC.ITC.hotel.orig_hot_num_xsl+' , \''+parseInt(itc+1)+'\' , '+parseInt(package_idx+1)+' , '+parseInt(air+1)+' , '+parseInt(opt+1)+');">'+lang['book']+'</button>';
var a = 1, b = 6;
var r = 'Result';
r += ': ' + parseInt(a+1) + ', ' + parseInt(b+1);
document.body.innerHTML = r;
Upvotes: 2