Bob Schneider
asked on
Getting Javascript value into an ASP form submission
I am trying to get the exact time a classic asp form submit is clicked. I want to get the time on the client side so that, if there is a delay getting to the server, the time is already stored. Below is what someone on this forum gave me. I closed the post before I implemented it. Can someone tell me why it is not submitting the "time" value please? Thanks so much!
Here is the server side code:
It returns nothing. Can someone tell me what I can do to resolve this please?
<hr>
<form role="form" class="form-inline" name="set_start" method="post"
action="set_time.asp?software=<%=sSoftware%>&event_id=<%=lEventID%>&race_id=<%=lRaceID%>">
<input type="hidden" id="time" name="time">
<input type="hidden" name="submit_start" id="submit_start" value="submit_start">
<input type="submit" class="form-control bg-success" name="get_start" id="get_start" value="Set Time Now!"
style="height:150px;font-weight:bold;font-size:1.5em;">
</form>
<%End If%>
<%End If%>
<%End If%>
</div>
<script>
document.getElementsByTagName("form")[0].onsubmit = function() {
document.getElementById("time").value = new Date().getTime(); // number of millisecond from 01/01/1970
}
</script>
</body>
Here is the server side code:
dDateTime = Request.Form.Item("time")
It returns nothing. Can someone tell me what I can do to resolve this please?
ASKER
I'm sorry. I thought I did accept your solution. It is exactly what I am looking for. My apologies. I tried that and I got no return beyond "time sent is : "
Post the rendered HTML.. at the first glance it looks okay.
p.s. but this will not give you the "exact time". Getting exact time stamps is hard science..
p.s. but this will not give you the "exact time". Getting exact time stamps is hard science..
could you add some code, you must get an alert with some info :
<script>
document.getElementsByTagName("form")[0].onsubmit = function() {
var t = new Date().getTime();
alert("field 'time' is " + (document.getElementById("time") ? 'not ' : '' ) + "found!\time is :" + t);
document.getElementById("time").value = t; // number of millisecond from 01/01/1970
}
</script>
ASKER
When i use that script I get this output...but it is on the first form of the page...The input 'time' is in the 4th form on the page.
field 'time' is found! ime is :1572889523822
field 'time' is found! ime is :1572889523822
ASKER
Here is the html:
<body>
<div class="container">
<h3 class="h3">Set GSE Race Start Times</h3>
<form role="form" class="form-inline" name="which_software" method="post" action="set_time.asp">
<select class="form-control" name="software" id="software" onchange="this.form.get_software.click()">
<option value="">Select Software</option>
<%If CStr(sSoftware) = CStr("RaceWare") Then%>
<option value="RaceWare" selected>RaceWare</option>
<option value="CCMeet">CCMeet</option>
<%ElseIf CStr(sSoftware) = CStr("CCMeet") Then%>
<option value="RaceWare">RaceWare</option>
<option value="CCMeet" selected>CCMeet</option>
<%Else%>
<option value="RaceWare">RaceWare</option>
<option value="CCMeet">CCMeet</option>
<%End If%>
</select>
<input type="hidden" name="submit_software" id="submit_software" value="submit_software">
<input type="submit" class="form-control" name="get_software" id="get_software" value="Go">
</form>
<%If Not sSoftware = vbNullString Then%>
<hr>
<form role="form" class="form-inline" name="which_event" method="post"
action="set_time.asp?software=<%=sSoftware%>">
<select class="form-control" name="events" id="events" onchange="this.form.get_event.click()">
<option value="">Select Event</option>
<%For i = 0 to UBound(Events, 2) - 1%>
<%If CLng(lEventID) = CLng(Events(0, i)) Then%>
<option value="<%=Events(0, i)%>" selected><%=Events(1, i)%></option>
<%Else%>
<option value="<%=Events(0, i)%>"><%=Events(1, i)%></option>
<%End If%>
<%Next%>
</select>
<input type="hidden" name="submit_event" id="submit_event" value="submit_event">
<input type="submit" class="form-control" name="get_event" id="get_event" value="Go">
</form>
<%If CLng(lEventID) > 0 Then%>
<hr>
<form role="form" class="form-inline" name="which_race" method="post"
action="set_time.asp?software=<%=sSoftware%>&event_id=<%=lEventID%>">
<select class="form-control" name="races" id="races" onchange="this.form.get_race.click()">
<option value="">Select Race</option>
<%For i = 0 to UBound(Races, 2)%>
<%If CLng(lRaceID) = CLng(Races(0, i)) Then%>
<option value="<%=Races(0, i)%>" selected><%=Races(1, i)%> (<%=Races(2, i)%>)</option>
<%Else%>
<option value="<%=Races(0, i)%>"><%=Races(1, i)%> (<%=Races(2, i)%>)</option>
<%End If%>
<%Next%>
</select>
<input type="hidden" name="submit_race" id="submit_race" value="submit_race">
<input type="submit" class="form-control" name="get_race" id="get_race" value="Go">
</form>
<%End If%>
<%If CLng(lRaceID) > 0 Then%>
<%If bIsLocked = True Then%>
The start time for this race has been set. No further changes will be recorded.
<br>
<div class="bg-success" style="font-weight:bold;text-align:center;">
Start Time For <%=sRaceName%>:
<br>
<%=dRaceStart%>
</div>
<%Else%>
<hr>
<form role="form" class="form-inline" name="set_start" method="post"
action="set_time.asp?software=<%=sSoftware%>&event_id=<%=lEventID%>&race_id=<%=lRaceID%>">
<input type="hidden" id="time" name="time">
<input type="hidden" name="submit_start" id="submit_start" value="submit_start">
<input type="submit" class="form-control bg-success" name="get_start" id="get_start" value="Set Time Now!"
style="height:150px;font-weight:bold;font-size:1.5em;">
</form>
<%End If%>
<%End If%>
<%End If%>
</div>
<script>
document.getElementsByTagName("form")[0].onsubmit = function() {
var t = new Date().getTime();
alert("field 'time' is " + (document.getElementById("time") ? 'not ' : '' ) + "found!\time is :" + t);
document.getElementById("time").value = t; // number of millisecond from 01/01/1970
}
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try something simple first :
<form role="form" class="form-inline" name="set_start" method="post" action="test.asp'>
with test.asp :
Open in new window