0

Problem

I use popup calendar, which is launched via href. I need to pass 'document.tstest.timestamp' (date input field) parameter into javascript function. And all worked well, BUT: I want to include this tag-file into another form, so I can't use form

<form name="tstest">

in my tag file. As a result, without form I can't find document.timestamp input-field (as I understand due window.object hierarchy)

My tag file:

<form name="tstest">
        <input type="Text" id="time_stamp" name="timestamp">
        <a href="javascript:show_calendar('document.tstest.timestamp',
                 document.tstest.timestamp.value);"> showCalendar</a>
</form>

<script>
    function show_calendar(target, value) {
        ............
    }
</script> 

Help me, please, to find out solution.

4

3 回答 3

0

您的元素上有一个id属性,因此您可以使用它document.getElementById()来获取对它的引用。不过,我建议修改您的show_calendar函数以id直接获取或引用元素,因为您可能需要在该函数内部再次引用它。

于 2013-03-31T23:47:58.590 回答
0

您应该能够在页面上的任何位置执行以下操作并获取元素:

var elem = document.getElementById("time_stamp");
var myVal = elem.value;

这也可以

<a href="javascript:show_calendar('document.tstest.timestamp',
             document.getElementById('time_stamp').value);"> showCalendar</a>
于 2013-03-31T23:48:16.587 回答
0

不要使用 document.tstest 作为语法,而是使用 document.getElementById("time_stamp")

还要记住一个 id 是唯一的,所以不要把两个相同的元素放在同一个页面上

于 2013-03-31T23:49:45.717 回答