简体   繁体   中英

How to pass javascript textBox value to URL as parameter

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM