Okay, so I've read several tutorials, plus a book on HTML5, which talks a lot about form controls and how much they've changed. So, I've tried testing the code out using this example code. What I want to do is send the form data (specifically a text field for the name of an event that someone wants to count down to and a datetime control for the date and time of the event) to the other HTML5 file for the JavaScript in the file to parse. The problem? The data is not being sent to the file that was specified as the form action!
Here is the code from the HTML file with the form in it (countdown_form.html):
<!DOCTYPE html>
<html>
<head>
<title>Collecting countdown data</title>
</head>
<body>
<form method="post" action="countdown.html">
<table border="1" cellpadding="5">
<tr>
<td>Name of event to count down to</td>
<td><input name="event" type="text"></td>
</tr>
<tr>
<td>Date of event to count down to</td>
<td><input name="date" type="datetime"></td>
</tr>
</table>
<input name="Submit" type="submit">
</form>
</body>
</html>
And here is the code from the HTML file that I am trying to send the form data to (countdown.html):
<!DOCTYPE html>
<html>
<head>
<title>
<script type="text/javascript">
document.write("Countdown to " + input.text);
</script>
</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<td>
<script type="text/javascript" language="JavaScript">
<!--
document.write("Time left until " + input.text);
//-->
</script>
</td>
</tr>
<tr>
<td>
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
dateFuture = new Date(input.date);
function GetCount(){
dateNow = new Date(); //grab current date
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;
// time is already past
if(amount < 0){
document.getElementById('countbox').innerHTML="Now!";
}
// date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";
amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
days=Math.floor(amount/86400);//days
amount=amount%86400;
hours=Math.floor(amount/3600);//hours
amount=amount%3600;
mins=Math.floor(amount/60);//minutes
amount=amount%60;
secs=Math.floor(amount);//seconds
if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
out += secs +" seconds";
document.getElementById('countbox').innerHTML=out;
setTimeout("GetCount()", 1000);
}
}
window.onload=function(){
GetCount();
}; //call when everything has loaded
//-->
</script>
<div id="countbox"></div>
</td>
</tr>
</table>
</body>
</html>
What I want to know is:
- Is it legal for one HTML document to send form data directly to another HTML document,
- If it is legal, how come the data from the <input> tags isn't being parsed by the input.text and input.datetime JavaScript variables inside the action document?
Also,
- Is it legal to have JavaScript code inside <title> tags?
- If it is legal, how come Google Chrome isn't parsing the code?
And if neither of these two things are legal, how exactly would you use form data as:
- The title of a document.
- As data for JavaScript to parse?