...

View Full Version : String together input from a form to create a URL



Keekmo
01-17-2005, 06:13 AM
I'm new to JavaScript. I created a simple HTML page on our LAN, and I am trying to create a link from this page to a daily spreadsheet (YYYYMMDD.xls) on the same LAN. I want to create a form with three input boxes (yyyy, mm, dd) that the user can submit in order to open older versions of the document. We use the following script to open the current document:

<script>
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yyyy = date.getFullYear();
var yyyymmdd = yyyy.toString() + month.toString() + day.toString();
document.write("<font face='Verdana'><font color='#000066'><font size=-1><b><u><a href='L:/main/Status/" + yyyymmdd + ".xls' target='_blank'>Click Here For Today's Status</a></u></b>");
</script>


Older documents are moved out of the 'Status' directory. For example, the document from March 15, 2004 would be
L:/main/Status/2004/2004_03/20040415.xls. Can I capture three input date fields and then use them to create a new <a href> tag? For example:

<a href='L:/main/Status/" + yyyy + "/" + yyyy + "_" + mm + "/" + yyyymmdd + ".xls' target='_blank'></a>

Kor
01-17-2005, 01:51 PM
Try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function stat(){
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yyyy = date.getFullYear();
var yyyymmdd = yyyy.toString() + month.toString() + day.toString();
window.open('L:/main/Status/'+yyyymmdd+'.xls','newp')
}
function newstat(){
var yyyy = document.getElementById('txy').getAttribute('value');
var mm = document.getElementById('txm').getAttribute('value');
var dd = document.getElementById('txd').getAttribute('value');
window.open('L:/main/Status/'+yyyy+'/'+yyyy+'_'+mm+'/'+yyyy+mm+dd+'.xls','newp')
}
</script>
</head>
<body>
<font face="Verdana" color="#000066" font size="-1"><b><u><a href="#" onclick="stat();return false">Click
Here For Today's Status</a></u></b></font> <br>
<br>
Enter new date:<br>
yyyy
<input type="text" id="txy"><br>
mm
<input type="text" id="txm"><br>
dd
<input type="text" id="txd">
<br>
<br>
<font face="Verdana" color="#000066" font size="-1"><b><u><a href="#" onclick="newstat();return false">Click
Here For The New Date's Status</a></u></b></font>
</body>
</html>

Keekmo
01-17-2005, 08:34 PM
That did it. Thanks a lot!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum