Jump to content

Timing an HTML form


vigiw

Recommended Posts

Hi there,

How do I make it so my HTML form can have a hidden field or something that is keeping track of the time it takes to complete the entire form?

I am working on an application that requires experience, so it will be an online test/exam.

If anyone could help me out, that would be great, thanks!!!  All help is appreciated!  :)
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/
Share on other sites

You could set a session variable (make it an array) and record the time the request was recieved to display the next page in the exam.

OR

you could use javascript to do the same thing - record start/stop time for each page

either way you don't need a hidden field to achieve it.
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71550
Share on other sites

have a look look at the Timing event in an infinite loop - with a Stop button example on this page. [url=http://www.w3schools.com/js/js_timing.asp]http://www.w3schools.com/js/js_timing.asp[/url]

everything you need is in there.  Just change the script so that tht timer starts on page load (onLoad in the body tag) and add the onClick event to your submit button.
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71556
Share on other sites

I think it would be better tohave the form on your server and just send a link to it in the e-mail.  depending on where the users accesses the form js may be disabled.

You will also have to check that js in enabled on the page the script is running on - which is why I think you should use the server to monitor the times via the sesion variable that way you don't have to worry about js being on or off.
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71570
Share on other sites

The file is on my server, it is on the web right now at my site (see http://www.vigilantweather.com/forecast/tester.html) -- the results are sent to my e-mail address is what I meant.

I am pretty sure JS is on, because I use scripts quite a bit.  I am writing this with MS Frontpage 2003.
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71575
Share on other sites

its not whether js is on on your machine - its whether the person filling in the form has js on.

One way of ensuring they have js on when answering is to use js to produce the submit button using document.write('<input type="sumit" ....

Having looked at your html....

change <body><onload="timedcount">

to <body onLoad="timedCount();">

remove the document.getelementbyid line in the timed count function.

and add a semicolon after the stopCount() in the onClick event of the submit button.

The action of your form MUST point to something cabale of processing the data in the manner you want.

../_vti_bin/shtml.exe/forecast/tester.html can that send an email? (i know is an exe but I have never used a method liek that - suppose thats why I use php ;) )

Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71589
Share on other sites

It can send e-mail, but each time you have entered data in the form, and I, still nothing, even after the edits!

By the way,

when I add document.write it shows up as text, so here is my current line for the submit button, think you could improvise?

  <input type="submit" value="Submit!" name="Submit" onClick="stopCount()";>

I am getting the e-mail, but it is not working (what I want to work-->the timer).

Will PHP work, like you said, you prefer it.  I don't know how to code for the PHP form though, I am more so a simple HTML form person.

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71593
Share on other sites

Kinda my bad here.

you need to set a variable equal to the time AND (embarrassed) have a hidden field of that variable name.

so put in anywhere in your form <input type="hidden" name="timetaken" id="timetaken" value="">

then the onSubmit attribute of the form put onSubmit="setTimetaken()"

and add thsi function in the js in the head of the page (under your timedCount function)

function setTimetaken () {
document.getElementById('timetaken').value = c;
}
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71595
Share on other sites

Shouldn't make any difference BUT just thought you don't need the new setTime taken function.

Cut and paste the document.getElementById line into the stopCount function and delete the setTimetaken function and all references to it.

As for the email - check that the variable names match in the script that processes the data.
Link to comment
https://forums.phpfreaks.com/topic/16979-timing-an-html-form/#findComment-71729
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.