[Javascript] Survey and elapsed time behind the scenes

Chris T christ at saeweb.com
Fri Jun 4 08:13:56 CDT 2004


Overall this looks good, but why require a browser that requires the use of
getElementById?  Surely that's not needed when fields can be referenced
through collections which have been around for quite some time - as well as
the date object...

Chris Tifer


> <form name="SurveyForm" id="SurveyForm" action="...">
>          <input type="hidden" name="BeginTime" id="BeginTime" value="" />
>          <input type="hidden" name="EndTime" id="EndTime" value="" />
> </form>
>
>
> window.onload = StartTimer
>
> function StartTimer()
> {
>                  if (!document.getElementById)
>                  {
>                          alert("Sorry, this survery requires a more modern
> browser"
>                          return
>                  }
>
>          // time-stamp hidden field
>          TimestampHiddenField("BeginTime")
>
>          // set the onsubmit event
>          var oForm = document.getElementById("SurveyForm")
>          oForm.onsubmit = StopTimer
> }
>
> function StopTimer()
> {
>          // time-stamp hidden field
>          TimestampHiddenField("EndTime")
>
>          // submit the form
>          return true
> }
>
> function TimestampHiddenField(argId)
> {
>          var oField = document.getElementById(argId)
>          var dNow = new Date()
>          oField.value = dNow.getTime()
> }
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list