Function with multiple parameters as argument in setTimeout

Function with multiple parameters as argument in setTimeout

Hi. I have written the following code (quite meaningless. Just to check why setTimeout is not working in a similar real-life code) to enable the user to input a given time interval (hh:mm:ss) when a p is clicked, and then alerting the user with the time entered in the seconds portion one second after the div is clicked. But it is not working. I think the setTimeout is the culprit, the way I am passing parameters to the function inside it, but don't know where exactly am I erring. Can anyone help?

  1. <html>
    <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("p").one("click",function() {
    var text=prompt("Enter the delay: ","Enter the delay: ");
    hr= parseInt(text.slice(0,2));
    min=parseInt(text.slice(3,5));
    sec=parseInt(text.slice(6));
    });
    $("#targett").one('click', function() {
    setTimeout("calc("+hr+","+min+","+sec+")",1000);
    });
    function calc(a,b,c) {
    alert(c);
    }
    });
    </script>
    </head>
    <body>
    <p>Click me!</p>
    <div id="targett">I am to be clicked.</div>
    </body>
    </html>