tomdelauro Posted February 12, 2009 Share Posted February 12, 2009 Hi all,Im trying to create a check on a form i have built that basically prompts me to fill in a text field if there is nothing in the field by a certain time, so for example there is a text field for 9:30 and what i want is for a prompt to come up if nothing has been filled in by 9:30, so it has to be linked to the real time, any ideas, i really need help on this one, short deadline.Thanks Tommy D Link to comment Share on other sites More sharing options...
jeffman Posted February 12, 2009 Share Posted February 12, 2009 Attach setInterval to a function that gets the time and compares it to the input value. When time's up, flash your alert and clear or reset your interval. Link to comment Share on other sites More sharing options...
tomdelauro Posted February 13, 2009 Author Share Posted February 13, 2009 Hi Mate,Thanks for the reply, can you be a bit more specific as i am a begginer at coding, maybe give me some sample code of a text box and it being validated again a certain time, i.e. if 9:30 and text box = null show alert, i think if i had an example i would be able to work out how i can apply it to my form ? Link to comment Share on other sites More sharing options...
jeffman Posted February 13, 2009 Share Posted February 13, 2009 This doesn't do what you want, but you can easily adapt it. You'll want to explore the Date object a bit more: <script type="text/javascript"> function start_timer () { var d = new Date(); var t = d.getTime(); if (d < start_time + (1000 * 10 * 1) ) { // ten seconds return; } var val = document.getElementById("my_input").value; if (val == "") { clearInterval(interval); alert ("You must complete the text item."); } } var interval; var start_time; function init () { var date = new Date(); start_time = date.getTime(); interval = setInterval (start_timer, 500); } window.onload = init;</script>* * *<label>Type something: </label><input type="text" id="my_input"> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.