0

I would like to pass the value from a date and time picker as a parameter to a URL. This is what I have:

<div style="text-align:left; margin:8px 5px auto;">
        <label for="dt_id">Please enter a date and time </label>
        <input type="Text" id="dt_id" maxlength="25" size="25"/>
        <img src="../../js/datetimepicker/images2/cal.gif" onclick="javascript:NewCssCal('dt_id','yyyyMMdd','arrow','true','24')" style="cursor:pointer"/>
        <input type='button' onclick='setURL()' value='SUBMIT'> 
</div>

<script>
var dt_value = document.getElementById("dt_id").value;
var sjdurl =  "/path/script?datetime="+dt_value;
</script>

However, the URL does not include the date value.

3
  • your JS code should be inside setURL() function.. Commented Nov 21, 2012 at 13:44
  • I would check with alert(dt_value) or console.log(dt_value) to see if you're picking up the value at all first, then go from there. Commented Nov 21, 2012 at 13:45
  • Also, does something appear in the URL at all or nothing? You may need to be using encodeURI and decodeURI [ developer.mozilla.org/en-US/docs/JavaScript/Reference/… ] Commented Nov 21, 2012 at 13:47

1 Answer 1

4

i tried to reproduce the scenario and it was completely working for me :-

<html>
<head>
<script>
    function setURL(){
    var dt_value = document.getElementById("dt_id").value;
    //just test here ..what is coming..
    alert(dt_value );
    var sjdurl =  "www.google.com?datetime="+dt_value;

popup = window.open(sjdurl,"popup"," menubar =0,toolbar =0,location=0, height=900, width=1000"); 
popup.window.moveTo(950,150); 

    }
</script>
</head>
<body>
<div style="text-align:left; margin:8px 5px auto;">
        <label for="dt_id">Please enter a date and time </label>
        <input type="Text" id="dt_id" maxlength="25" size="25"/>
        <input type='button' onclick='setURL()' value='SUBMIT'> 
</div>

</body>
</html>
Sign up to request clarification or add additional context in comments.

5 Comments

Oops I forgot to mention: I am using the url in popup function : popup = window.open(sjdurl,"popup"," menubar =0,toolbar =0,location=0, height=900, width=1000"); I have also used the alert(dt_value) to check and the value is correct!
sjd.node.onclick = function () { popup = window.open(sjdurl,"popup"," menubar =0,toolbar =0,location=0, height=900, width=1000"); popup.window.moveTo(950,150); if (window.focus){popup.focus}; };
Two thing :- 1> how you are setting the var sjdurl, inside a setURL function or globally. if inside a SetURL function then how you are accessing that variable in openpopup function because it will be out of scope.2> if globally then how you are setting the variable.?
Problem Solved. My onclick function was outside of the setURL function.
very good if it is solved ..but if my answer has helped you then you should Vote up and accept the answer.

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.