Jump to content

Archived

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

vigiw

Timing an HTML form

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!  :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Hello,

Thanks for your input!  Javascript sounds easier, so I will try that out.  Do you have a code to do so, or know where I could find one?  I am not a good code-maker, a better form maker and paster. ;)

Please let me know, or anyone else out there!

Thanks again!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sorry for the late reply, I was making a sample form.  I am testing it out but thought of something:

How do I get the time start and end to be saved in the form results?

I sent the form to my e-mail address and I only got the multiple choice questions, not the times.

Thanks.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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 ;) )

Share this post


Link to post
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.

Share this post


Link to post
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;
}

Share this post


Link to post
Share on other sites
That's ok..

Hmm... getting there...

This was in the form results e-mailed to me:

timetaken:     

No number, but there are many spaces after the "timetaken:" in the e-mail (highlight this post, above, I included the spaces)

Any thoughts?
Thanks.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.