Aurelijus1 Aurelijus1 - 3 months ago 8
HTML Question

How to define value in javascript

I tried to use $(".input-text").val() to define value but all code stop working, maybe there is other way that i can define it from input text? Here is that line:

$(document).ready(function(){
var oMain = new CMain({
howmuch: $(".input-text").val()
});


Only works if i put number instead of $(".input-text").val()

Answer

$(".input-text").val() returns string, so if CMain expects integer in howmuch you need to convert value to integer:

howmuch: parseInt($(".input-text").val())
Comments