PDA

View Full Version : Help with Web From



kevenj
Mar 26th, 2003, 08:18 PM
Can someone help me with this?

I am trying to incorporate mutliple javascripts into one form
to get my desried result:

First, Can anyone tell me why this will NOT display
the month:

<SCRIPT language="JavaScript">
today = new Date();
document.writeln(today.getMonth()+today.getDate() +", " +today.getYear())
</SCRIPT>
and how do I display the above result in a particular text filed of my form labled date, which will ultimatley be stored in a db?

Lastly, I have created an array that is essentially a drop down list. When the user selects one of the options I am trying to get some text associated with that array in a text field. I can do it but the text field is very looong. How do I get the text to wrap instead.Here is the code:

<SCRIPT LANGUAGE="JavaScript">
// the data
var regionalOffices = new Array("Sales, Promotions, & Operations", "General Mgr, Business Office, Corporate Mgmt, Exec. Asst., Sales Mgmt, Promotions Dir, Station Mgr, Traffic", "Programming, Engineering, Program Dir, News Dir")
var regionalManagers = new Array("Compaq EVO D510 Small Form Factor, 2.0+Ghz,40GB Hard Drive,256MB Memory,CD-Rom,3 Year Warranty", "Compaq EVO D510 Mini-Tower CMT,2.0+Ghz,40GB Hard Drive,256MB Memory,CD-Rom,3 Year Warranty", "Compaq EVO D510 Mini-Tower CMT +, 2.0+Ghz, 80GB Hard Drive, 512MB Memory, CD/RW, 3 Year Warranty")

// do the lookup into parallel arrays
function getData(form) {
var i = form.offices.selectedIndex
form.manager.value = regionalManagers[i]
}
</SCRIPT>

</HEAD>

<BODY onLoad="getData(document.officeData)">
<H1>Purchase Requisition Form</H1>
<HR>
<FORM NAME="officeData">
omputer is For:
<SELECT NAME="offices" onChange="getData(this.form)">
<OPTION>Sales, Promotions, & Operations
<OPTION>General Mgr, Business Office, Corporate Mgmt, Exec. Asst., Sales
Mgmt, Promotions Dir, Station Mgr, Traffic
<OPTION>Programming, Engineering, Program Dir, News Dir
</SELECT>
</p></P>
<P>
<INPUT TYPE="text" NAME="manager" SIZE=135>
</P>
<P>
<input type="reset" name="Reset" value="Reset">
</P>
<P><BR>
</P>
</FORM>
</BODY>
</HTML>

thanks

chrismiceli
Mar 26th, 2003, 11:57 PM
Originally posted by kevenj
First, Can anyone tell me why this will NOT display
the month:

<SCRIPT language="JavaScript">
today = new Date();
document.writeln(today.getMonth()+today.getDate() +", " +today.getYear())
</SCRIPT>
and how do I display the above result in a particular text filed of my form labled date, which will ultimatley be stored in a db?

can't tell you how to store in database, but mabey this will help


<SCRIPT language="JavaScript">
today = new Date();
month = today.getMonth();
date = today.getDate();
year = today.getFullYear();
document.formname.elementname.value = month.toString() + date.toString() + " , " + year.toString();
</SCRIPT>

kevenj
Mar 27th, 2003, 12:33 AM
Thanks for the reply:

My question is with the last part:

document.formname.elementname.value = month.toString() + date.toString() + " , " + year.toString();
</SCRIPT>

Can I set a text field to display the result above. I tried
the following:

<form name="req">

<SCRIPT language="JavaScript">
today = new Date();
month = today.getMonth();
date = today.getDate();
year = today.getFullYear();

<input name="td" type="text" Value = month.toString() + date.toString() + " , " + year.toString(); >


</SCRIPT>
</form>

But it will not display. Just will be just the first field in the form.

Thanks

hogtied
Mar 27th, 2003, 01:04 AM
you can do this

var form = document.formname;

form.elementname.value = month.toString() + date.toString() + " , " + year.toString();

form.td.value = form.elementname.value;
</SCRIPT>

glenngv
Mar 27th, 2003, 02:37 AM
<form name="req">

<script language="javascript">
var today = new Date();
var arrMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
document.write('<input name="td" type="text" value="' + arrMonth[today.getMonth()] + ' ' + today.getDate() + ', ' + today.getFullYear() + '">');
</script>

</form>

or put the date onload:

<head>
<script language="javascript">
function setDate(){
var today = new Date();
var arrMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
document.req.td.value = arrMonth[today.getMonth()] + ' ' + today.getDate() + ', ' + today.getFullYear();
}
</script>

</head>
<body onload="setDate()">
<form name="req">

<input name="td" type="text">

</form>
</body>

cheesebagpipe
Mar 27th, 2003, 02:46 AM
My tuppence...

<html>
<head>
<script type="text/javascript">

var regionalManagers = new Array(" Compaq EVO D510 Small Form Factor, 2.0+Ghz, 40GB Hard Drive, 256MB Memory, CD-Rom, 3 Year Warranty", " Compaq EVO D510 Mini-Tower CMT, 2.0+Ghz, 40GB Hard Drive, 256MB Memory, CD-Rom, 3 Year Warranty", " Compaq EVO D510 Mini-Tower CMT +, 2.0+Ghz, 80GB Hard Drive, 512MB Memory, CD/RW, 3 Year Warranty");

function setField(form) {
var i = 0, usage = form.usage;
for (i; i<usage.length; i++) if (usage[i].checked) {
form.manager.value = regionalManagers[i].split(',').join('\n');
return;
}
form.manager.value = '';
}

</script>
</head>
</head>
<BODY onload="setField(document.officeData)">
<H1>Purchase Requisition Form</H1>
<HR>
<FORM NAME="officeData">
<b>Computer is For:</b><br /><br />
<input type="radio" name="usage" checked="checked" onclick="setField(this.form)" />Sales, Promotions, & Operations<br /><br />
<input type="radio" name="usage" onclick="setField(this.form)" />General Mgr, Business Office, Corporate Mgmt, Exec. Asst., Sales
Mgmt, Promotions Dir, Station Mgr, Traffic<br /><br />
<input type="radio" name="usage" onclick="setField(this.form)" />Programming, Engineering, Program Dir, News Dir<br /><br />
<textarea rows="6" cols="35" NAME="manager" readonly="readonly"></textarea><br /><br />
<input name="date" type="text" size="30" />
<br /><br />
<input type="reset" name="Reset" value="Reset">
</P>
<P><BR>
</P>
</FORM>
<script type="text/javascript">
today = new Date().toLocaleString();
document.officeData.date.value = ' ' + today.substring(0,today.indexOf(':')-2);
</script>
</BODY>
</HTML>

kevenj
Mar 27th, 2003, 03:41 AM
THANK YOU!!

I have been looking at this for about 12 hours now.

YOU RULE