0

Hi i have this change function in jquery when selecting the time, the time will calculate to four hours. Upon selecting using change function the time and calculate for four hours works well. Now my problem is how will i able to pass the value to my .html()

Here is my script below:

 $('#changeTime').change(function() {
            $("#checkoutT").hide();
            var time = $(this).val();


            var timeArr = time.split(":");

            var timevar = timeArr[0];

            var x = <?php echo $minStayExp[0] ?>;
            var calc = parseInt(timevar) + parseInt(x);

            console.log(timevar);
            console.log(calc);
            alert(calc);


            $("#checkoutTime").html('<p class="text-sm text-muted"></p>');


         });

Now i want my value in my var calc will passed to .html() line of code in here:

$("#checkoutTime").html('<p class="text-sm text-muted"> + calc +</p>');

Something like this.

Can someone help me figured this thing out? Any help is muchly appreciated. TIA

5
  • 1
    basic string concatenation. '<p class="text-sm text-muted">' + calc + '</p>' You did not close the strings.... Commented Dec 11, 2019 at 15:45
  • thank you i forgot its concatenation Commented Dec 11, 2019 at 15:47
  • it works now! thanks Commented Dec 11, 2019 at 15:47
  • Does this answer your question? how to use variable in string in jquery Commented Dec 11, 2019 at 15:47
  • Yes it answers my question Commented Dec 11, 2019 at 15:51

3 Answers 3

4

You need to concat.

$("#checkoutTime").html('<p class="text-sm text-muted">' + calc +'</p>');
Sign up to request clarification or add additional context in comments.

Comments

4

You can use string interpolation:

$("#checkoutTime").html(`<p class="text-sm text-muted">${calc}</p>`);

Comments

0

There was an error in your concatenation

'<p class="text-sm text-muted">' + calc + '</p>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.