Click to See Complete Forum and Search --> : date/submit


tiger66
07-08-2003, 08:45 AM
Hi
I am just wondering how can I use js to generate the current date
Also how can I write js for a button to submit a form?

Thanks

freefall
07-08-2003, 08:57 AM
There's a couple ways you could do the date, here's an example, month date, year. Put this is the <body> section

<script type="text/javascript">
var d = new Date();
var month = d.getMonth(); // month of year (0-11)
var date = d.getDate(); // day of month (1-31)
var year = d.getFullYear(); // full year (20xx)
var monthName = new Array("Jan.","Feb.","Mar.","Apr.","May","June","July","Aug.","Sep.","Oct.","Nov.","Dec.");

document.write("The current date is: "+ monthName[month] +" "+ date +", "+ year);
</script>


Also in the <body> section, a submit button:

<script type="text/javascript">
document.write('<input type="submit" value="Submit">');
</script>


Is this what you wanted? Hope I've helped!
- Ian

tiger66
07-08-2003, 09:07 AM
Thanks
I like the way you format the date
for form submission, I have a input type=button
I am trying to write an onClick = "blah" to submit a form

Thanks again

freefall
07-08-2003, 09:16 AM
Like this? I think this is what yu mean, right?
<input type="button" value="Submit" onclick="submit()">

- Ian

Charles
07-08-2003, 11:57 AM
All you need is something as simple as what follows. It will not work for the 13% of users who do not use JavaScript which is also why it is very to submit your form using JavaScript. Use a submit button.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<form action="" onsubmit="this.date.value = new Date()">
<div>
<input name="date" type="hidden" value="">
<input type="submit">
</div>
</form>