Forum Moderators: open
You will recieve your widget on [day, date].
I'm javascript ignorant, so I'm basically looking for something I can cut and post.
Anyone know where there might be such a script, or have one they could post?
I've searched around, but the things I have found were only snippets, and I lack the knowledge to get the things working.
[pre]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>widget delivery date</title>
</head>
<body>
<form name="myFormName" method="get" action=" ">
<h1>Widget Due Date</h1>
<noscript><div>Javascript must be enabled in your browser</div></noscript>
<p>Lorem ipsum dolor sit amet</p>
<script type="text/javascript">
var myDelayInDays=2; // adjust this value to suit
var myDate=new Date();
var oneDayInMilliseconds = (24*60*60*1000);
var myTimeInMillisconds=myDate.getTime()+(myDelayInDays * oneDayInMilliseconds);
myDate.setTime(myTimeInMillisconds);
/*
setTime() is an 'inbuilt' javascript function
that calculates a date and time by adding or subtracting
a specified number of milliseconds to/from midnight January 1, 1970
it can be buggy in some browsers
*/
var widgetDueDate = myDate.toLocaleDateString();
/*
toLocaleDateString() is an 'inbuilt' javascript function
that converts a Date object, according to local time,
to a string and returns the date portion
*/
document.write('<p>You will receive your widget in '
+ myDelayInDays
+ ' days, on <strong>'
+ widgetDueDate + '<\/strong><\/p>');
</script>
</form>
<p>Nam commodo libero nec justo. Sed diam risus, suscipit eu</p>
</body>
</html>[/pre]
Big Thank you.You're welcome
Took a while to copy it so I didn't mess up the commentsYou can, of course, delete the comments...
But... Yeah... Sorry about the indentation via spacebar-spacing...
For some reason I can't get my head around this forum software and the way it handles (or, maybe, doesn't handle) tab-spacing...
In order to preserve some sort of indentation, I simply 'find-and-replace' my tabs with a bunch of spaces :(
it looks like it works like a charmCool. And its valid HTML4- strict, too :)
Did you write this off the top of your head?almost... I have a few old files that do something very similar
what's the function of the form part?To be honest, I don't recall if it's (ever) 'required' or just 'recommended practice'...
In this case, on such a simple page, its probably a bit of overkill...
But...
On a more complex page, with 2 or more script sections, it can be handy to be able to address specific elements both by element-id AND by form-name - e.g. if/when you (might) have two elements with the same name (can easily happen if more than one person is writing/maintaining code!)
e.g
document.frmAlpha.selEmpName.selectedIndex
and
document.frmBravo.selEmpName.selectedIndex
address two distinct elements :)
At least... that's what I think the rationale is
Anyhoo... if it works, don't fix it is what I say :)