简体   繁体   English

如何将javascript textBox值作为参数传递给URL

[英]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. 我想将日期和时间选择器中的值作为参数传递给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. 但是,URL不包含日期值。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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