jquery - Concatenation of 4 input fields -
i new javascript world trying grab input value 4 separate input fields , concatenate them string end time, can use moments timezone output in various different destinations around world. trying concatenate 4 input's 1 when tested alert, display nan
. guidance great.
$(document).ready(function() { var time1 = $("#time--1").val(); var time2 = $("#time--2").val(); var time3 = $("#time--3").val(); var time4 = $("#time--4").val(); $('.btn').click(function(e) { e.preventdefault(); var time = time1.val + time2.val + time3.val + time4.val; alert(time); }); });
you're calling val()
retrieves value of field string or number, , you're calling val
on that, return undefined
. undefined + undefined == nan
.
just sum variables: var time = time1 + time2 + time3 + time4;
Comments
Post a Comment