View Full Version : How to display output not in a textbox
ktplaskett
04-29-2003, 07:28 PM
I'm trying to implement a script where it will show the date 7 days ahead of the current date. It's purpose is to show the date of which a customer's order will ship. They always ship within 7 days so all it does is show the date 7 days from now. My question is how to make the output direct instead of in a text box?
The script works, just need to figure out a way to not have it display in a textbox:
I appreciate any/all suggestions:
<HEAD><SCRIPT language="JavaScript">
function AddDays(form) {
DaysToAdd=document.form.DaysToAdd.value;
var now=new Date();
var newdate=new Date();
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
document.form.display.value=newdate.toLocaleString();
}
// End -->
</SCRIPT>
</head>
<body>
<center>
<form name=form>
<input type=hidden name=DaysToAdd size=5 value=7>
<BODY onLoad="javascript:AddDays();">
<input type=text name="display" size=35 value="">
</form>
requestcode
04-29-2003, 07:58 PM
Maybe this example will help:
<html>
<head>
<title>Display Date and Time</title>
</head>
<body>
<span id="liveclock" style="position:absolute;left:0;top:0;"></span>
<script language="JavaScript">
function showdatetime()
{
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var gyear=Digital.getFullYear()
var gmonth=Digital.getMonth()+1
var gday=Digital.getDate()
if(gday<10)
{gday="0"+gday}
if(gmonth<10)
{gmonth="0"+gmonth}
var dn="PM"
if (hours<12)
{dn="AM"}
if (hours>12)
{hours=hours-12}
if (hours==0)
{hours=12}
if (minutes<=9)
{minutes="0"+minutes}
if (seconds<=9)
{seconds="0"+seconds}
myclock="<font color=red size=-1><b>Current Time:"+hours+":"+minutes+":"+seconds+" "+dn+"</b></font>"
mydate="<font color=red size=-1><b>Current Date:"+gmonth+"/"+gday+"/"+gyear+"</b></font>"
timedate=myclock+"<br>"+mydate
if (document.layers) // ns4
{
document.liveclock.document.write(timedate)
document.liveclock.document.close()
}
if (document.all) // ie
{liveclock.innerHTML=timedate}
if (document.getElementById) // NS6
{document.getElementById("liveclock").innerHTML=timedate}
setTimeout("showdatetime()",1000)
}
window.onload=showdatetime
</script>
</body>
</html>
tamienne
04-29-2003, 08:13 PM
Here's another...
<html>
<HEAD><SCRIPT language="JavaScript">
function AddDays(DaysToAdd) {
var now=new Date();
var newdate=new Date();
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
//document.form.display.value=newdate.toLocaleString();
return newdate.toLocaleString();
}
function displayNewDate() {
document.write(AddDays(7));
}
function updateIframe(days) {
ifDate.document.open();
ifDate.document.write(AddDays(days));
ifDate.document.close();
}
// End -->
</SCRIPT>
</head>
<BODY onLoad="updateIframe(7)">
<center>
<script>
displayNewDate();
</script>
</center>
<BR><BR>
or if you want to define the number of days from an input box...
<BR><BR>
<FORM>
Days: <INPUT TYPE="text" NAME="numDays" VALUE="7" onChange="updateIframe(this.value)">
<INPUT TYPE="BUTTON" Value="Update Date">
</FORM>
<IFRAME NAME="ifDate" BORDER="0" marginwidth="0" frameborder="0"></IFRAME>
</body>
</html>
ktplaskett
04-29-2003, 08:25 PM
Thanks for the examples.. I'll play around with the 1st one. The 2nd one that was sent by tamienne is actually the same code I have.. it puts the output into a form box.
The main issue is that this script is to run inside a <form></form>. So any script that calls for it's own form isn't going to work.
The 1st script is quite close as to what I'm wanting to do.. although I am unable to make it work :confused:
Any other ideas out there?
requestcode
04-29-2003, 08:44 PM
Try the Free Scripts section of JavaScriptkit. They have several date scripts that you could probably modify. Here is a link:
http://www.javascriptkit.com/script/cutindex1.shtml
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.