cygnusx1z
05-28-2003, 01:24 PM
Hope someone can help.
I've built a form that has 5 fields. One of the fields is a text box into which I'm having a script input "today's" date by default. This script works fine alone. I then have a "cookie" that "remembers" the last entries for two other fields (name & work_func). This script also works fine when alone. The problem occurs when I combine the two (along with another script used for validation). The date field does not default to "today's" date or any other date for that matter. Here's what I've got:
<HTML>
<HEAD>
<TITLE>Center Tally</TITLE>
<!------------------Default Today's Date & Field Validation Scripts------------------------->
<SCRIPT LANGUAGE="JavaScript">
<!--
// redefine the default Date Format
Date.prototype.toString = function () {return [this.getMonth() < 10 ? '0' + (this.getMonth()+1) : (this.getMonth()+1), this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join('/')}
//Set the Date Field
onload = function () {electTallyForm.date.value = new Date()};
//Validate that fields are completed
function validateFields() {
errmsg = "";
if (document.electTallyForm.name.selectedIndex == 0) {
errmsg += "Please select a NAME\n";
}
if (document.electTallyForm.work_func.selectedIndex == 0) {
errmsg += "Please select a WORK FUNCTION\n";
}
if (document.electTallyForm.ordrnum.value == "") {
errmsg += "Please enter an ORDER NUMBER\n";
}
if (errmsg != "") {
alert (errmsg);
return false;
}
}
-->
</script>
</HEAD>
<BODY>
<!---------------------Cookie for Name & Work Function Fields------------------------>
<script language="JavaScript">
<!--
var never = new Date()
never.setTime(never.getTime() + 2000*24*60*60*1000);
// name is a string of the name of your cookie
// value is the value corresponding to name
function SetCookie(name, value) {
var expString = "; expires=" + never.toGMTString();
document.cookie = name + "=" + escape(value) + expString;
}
// returns value of cookie or null if cookie does not exist
function GetCookie(name) {
var result = null;
var myCookie = " " + document.cookie + ";";
var searchName = " " + name + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length; // skip past name of cookie
endOfCookie = myCookie.indexOf(";", startOfCookie);
result = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
return result;
}
use_cookies = "unsure";
function saveValue(element) {
if (document.images && use_cookies == "unsure")
use_cookies = (confirm("Will you allow the values you enter into this form "
+"to be stored as cookies so that those values will be pre-filled the next "
+"time you return to this page?") ? "yes":"no");
if (document.images && use_cookies == "yes") {
if ((element.type == "text")
|| (element.type == "password")
|| (element.type == "textarea")
|| (element.type == "radio")) {
val = element.value;
} else if (element.type.indexOf("select") != -1) {
val = "";
for(k=0;k<element.length;k++)
if (element.options[k].selected)
val += k+" ";
} else if (element.type == "checkbox") {
val = element.checked;
}
SetCookie("memory_"+element.form.name+"_"+element.name,val);
}
}
function storedValues() {
if (document.images) { // only do it in JavaScript 1.1 browsers
for (i=0;i<document.forms.length;i++) {
for (j=0;j<document.forms[i].elements.length; j++) {
cookie_name = "memory_"+document.forms[i].name+"_"
+document.forms[i].elements[j].name;
val = GetCookie(cookie_name);
if (val) {
if ((document.forms[i].elements[j].type == "text")
|| (document.forms[i].elements[j].type == "password")
|| (document.forms[i].elements[j].type == "textarea")) {
document.forms[i].elements[j].value = val;
} else if (document.forms[i].elements[j].type.indexOf("select") != -1) {
document.forms[i].elements[j].selectedIndex = -1;
while (((pos = val.indexOf(" ")) != -1) && (val.length > 1)) {
sel = parseInt(val.substring(0,pos));
val = val.substring(pos+1,val.length);
if (sel < document.forms[i].elements[j].length)
document.forms[i].elements[j].options[sel].selected = true;
}
} else if (document.forms[i].elements[j].type == "checkbox") {
document.forms[i].elements[j].checked = val;
} else if (document.forms[i].elements[j].type == "radio") {
if (document.forms[i].elements[j].value == val)
document.forms[i].elements[j].checked = true;
}
}
}
}
}
}
window.onload = storedValues;
// -->
</script>
<FORM NAME="electTallyForm" METHOD="POST" action="--WEBBOT-SELF--" onsubmit="return validateFields()">
<!--webbot bot="SaveResults" s-label-fields="TRUE" b-reverse-chronology="FALSE" s-builtin- fields u-file="tally_results_indy.txt" s-format="TEXT/CSV" startspan -->
<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0">
<!--webbot bot="SaveResults" endspan i-checksum="43374" -->
<DIV ALIGN="center">
<CENTER>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="1" width="479">
<TR ALIGN="right">
<TH BGCOLOR="#FFCC66" colspan="2" width="425"><p align="center">Center Tally Form</TH>
</TR>
<!------------------NAME------------------------------->
<TR ALIGN="right">
<TH BGCOLOR="#FFCC66" width="185"><font color="#FF0000">*</font>Name:</TH>
<TD BGCOLOR="#FFCC66" width="273"><p align="left">
<SELECT NAME="name" onChange="saveValue(this)">
<OPTION>--Select One--</OPTION>
<option value="1234567">Adams, Pam</option>
<option value="2345678">Zajac, Patricia</option>
</SELECT>
</TD>
</TR>
<!------------------DATE------------------------------->
<TR ALIGN="right">
<TH BGCOLOR="#FFCC66" width="185"><P ALIGN="right"><font color="#FF0000">*</font>Date:</TH>
<TD BGCOLOR="#FFCC66" ALIGN="left" width="273"><INPUT NAME="date" SIZE="12" onchange="this.value = new Date(this.value)"> <TT>MM/DD/YYYY</TT>
</TD>
</TR>
<!-----------------WORK FUNCTION------------------------>
<TR>
<TH BGCOLOR="#FFCC66" width="185"><p align="right"><font color="#FF0000">*</font>Work Function:</TH>
<TD BGCOLOR="#FFCC66" width="273">
<SELECT NAME="work_func" onChange="saveValue(this)">
<OPTION>--Select One--</OPTION>
<option>7.10 Launch</option>
<OPTION>Special Project</OPTION>
</SELECT>
</TD>
</TR>
<!----------------SPECIAL PROJECT------------------------>
<TR>
<TH BGCOLOR="#FFCC66" width="198"><P ALIGN="right">Special Project Name:</TH>
<TH BGCOLOR="#FFCC66" width="206"><P ALIGN="left"><INPUT TYPE="text" NAME="specproj" SIZE="20" VALUE="If Applicable"></TH>
</TR>
<!---------------ORDER NUMBER---------------------------->
<TR>
<TH BGCOLOR="#FFCC66" width="185"><P ALIGN="right"><font color="#FF0000">*</font>Order Number:</TH>
<TD BGCOLOR="#FFCC66" width="273"><INPUT TYPE="text" NAME="ordrnum" SIZE="20"></TD>
</TR>
<!--------------SUBMIT/RESET----------------------------->
<TR>
<TD COLSPAN="2" ALIGN="center" BGCOLOR="#FFCC66" width="425">
<INPUT TYPE="SUBMIT" VALUE="SEND">
<INPUT TYPE="RESET" VALUE="CLEAR">
</TD>
</TR>
</TABLE>
</CENTER>
</DIV>
</FORM>
</BODY>
</HTML>
I'd appreciate any help I can get.
Thanks!
CygnusX1
I've built a form that has 5 fields. One of the fields is a text box into which I'm having a script input "today's" date by default. This script works fine alone. I then have a "cookie" that "remembers" the last entries for two other fields (name & work_func). This script also works fine when alone. The problem occurs when I combine the two (along with another script used for validation). The date field does not default to "today's" date or any other date for that matter. Here's what I've got:
<HTML>
<HEAD>
<TITLE>Center Tally</TITLE>
<!------------------Default Today's Date & Field Validation Scripts------------------------->
<SCRIPT LANGUAGE="JavaScript">
<!--
// redefine the default Date Format
Date.prototype.toString = function () {return [this.getMonth() < 10 ? '0' + (this.getMonth()+1) : (this.getMonth()+1), this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join('/')}
//Set the Date Field
onload = function () {electTallyForm.date.value = new Date()};
//Validate that fields are completed
function validateFields() {
errmsg = "";
if (document.electTallyForm.name.selectedIndex == 0) {
errmsg += "Please select a NAME\n";
}
if (document.electTallyForm.work_func.selectedIndex == 0) {
errmsg += "Please select a WORK FUNCTION\n";
}
if (document.electTallyForm.ordrnum.value == "") {
errmsg += "Please enter an ORDER NUMBER\n";
}
if (errmsg != "") {
alert (errmsg);
return false;
}
}
-->
</script>
</HEAD>
<BODY>
<!---------------------Cookie for Name & Work Function Fields------------------------>
<script language="JavaScript">
<!--
var never = new Date()
never.setTime(never.getTime() + 2000*24*60*60*1000);
// name is a string of the name of your cookie
// value is the value corresponding to name
function SetCookie(name, value) {
var expString = "; expires=" + never.toGMTString();
document.cookie = name + "=" + escape(value) + expString;
}
// returns value of cookie or null if cookie does not exist
function GetCookie(name) {
var result = null;
var myCookie = " " + document.cookie + ";";
var searchName = " " + name + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length; // skip past name of cookie
endOfCookie = myCookie.indexOf(";", startOfCookie);
result = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
return result;
}
use_cookies = "unsure";
function saveValue(element) {
if (document.images && use_cookies == "unsure")
use_cookies = (confirm("Will you allow the values you enter into this form "
+"to be stored as cookies so that those values will be pre-filled the next "
+"time you return to this page?") ? "yes":"no");
if (document.images && use_cookies == "yes") {
if ((element.type == "text")
|| (element.type == "password")
|| (element.type == "textarea")
|| (element.type == "radio")) {
val = element.value;
} else if (element.type.indexOf("select") != -1) {
val = "";
for(k=0;k<element.length;k++)
if (element.options[k].selected)
val += k+" ";
} else if (element.type == "checkbox") {
val = element.checked;
}
SetCookie("memory_"+element.form.name+"_"+element.name,val);
}
}
function storedValues() {
if (document.images) { // only do it in JavaScript 1.1 browsers
for (i=0;i<document.forms.length;i++) {
for (j=0;j<document.forms[i].elements.length; j++) {
cookie_name = "memory_"+document.forms[i].name+"_"
+document.forms[i].elements[j].name;
val = GetCookie(cookie_name);
if (val) {
if ((document.forms[i].elements[j].type == "text")
|| (document.forms[i].elements[j].type == "password")
|| (document.forms[i].elements[j].type == "textarea")) {
document.forms[i].elements[j].value = val;
} else if (document.forms[i].elements[j].type.indexOf("select") != -1) {
document.forms[i].elements[j].selectedIndex = -1;
while (((pos = val.indexOf(" ")) != -1) && (val.length > 1)) {
sel = parseInt(val.substring(0,pos));
val = val.substring(pos+1,val.length);
if (sel < document.forms[i].elements[j].length)
document.forms[i].elements[j].options[sel].selected = true;
}
} else if (document.forms[i].elements[j].type == "checkbox") {
document.forms[i].elements[j].checked = val;
} else if (document.forms[i].elements[j].type == "radio") {
if (document.forms[i].elements[j].value == val)
document.forms[i].elements[j].checked = true;
}
}
}
}
}
}
window.onload = storedValues;
// -->
</script>
<FORM NAME="electTallyForm" METHOD="POST" action="--WEBBOT-SELF--" onsubmit="return validateFields()">
<!--webbot bot="SaveResults" s-label-fields="TRUE" b-reverse-chronology="FALSE" s-builtin- fields u-file="tally_results_indy.txt" s-format="TEXT/CSV" startspan -->
<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0">
<!--webbot bot="SaveResults" endspan i-checksum="43374" -->
<DIV ALIGN="center">
<CENTER>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="1" width="479">
<TR ALIGN="right">
<TH BGCOLOR="#FFCC66" colspan="2" width="425"><p align="center">Center Tally Form</TH>
</TR>
<!------------------NAME------------------------------->
<TR ALIGN="right">
<TH BGCOLOR="#FFCC66" width="185"><font color="#FF0000">*</font>Name:</TH>
<TD BGCOLOR="#FFCC66" width="273"><p align="left">
<SELECT NAME="name" onChange="saveValue(this)">
<OPTION>--Select One--</OPTION>
<option value="1234567">Adams, Pam</option>
<option value="2345678">Zajac, Patricia</option>
</SELECT>
</TD>
</TR>
<!------------------DATE------------------------------->
<TR ALIGN="right">
<TH BGCOLOR="#FFCC66" width="185"><P ALIGN="right"><font color="#FF0000">*</font>Date:</TH>
<TD BGCOLOR="#FFCC66" ALIGN="left" width="273"><INPUT NAME="date" SIZE="12" onchange="this.value = new Date(this.value)"> <TT>MM/DD/YYYY</TT>
</TD>
</TR>
<!-----------------WORK FUNCTION------------------------>
<TR>
<TH BGCOLOR="#FFCC66" width="185"><p align="right"><font color="#FF0000">*</font>Work Function:</TH>
<TD BGCOLOR="#FFCC66" width="273">
<SELECT NAME="work_func" onChange="saveValue(this)">
<OPTION>--Select One--</OPTION>
<option>7.10 Launch</option>
<OPTION>Special Project</OPTION>
</SELECT>
</TD>
</TR>
<!----------------SPECIAL PROJECT------------------------>
<TR>
<TH BGCOLOR="#FFCC66" width="198"><P ALIGN="right">Special Project Name:</TH>
<TH BGCOLOR="#FFCC66" width="206"><P ALIGN="left"><INPUT TYPE="text" NAME="specproj" SIZE="20" VALUE="If Applicable"></TH>
</TR>
<!---------------ORDER NUMBER---------------------------->
<TR>
<TH BGCOLOR="#FFCC66" width="185"><P ALIGN="right"><font color="#FF0000">*</font>Order Number:</TH>
<TD BGCOLOR="#FFCC66" width="273"><INPUT TYPE="text" NAME="ordrnum" SIZE="20"></TD>
</TR>
<!--------------SUBMIT/RESET----------------------------->
<TR>
<TD COLSPAN="2" ALIGN="center" BGCOLOR="#FFCC66" width="425">
<INPUT TYPE="SUBMIT" VALUE="SEND">
<INPUT TYPE="RESET" VALUE="CLEAR">
</TD>
</TR>
</TABLE>
</CENTER>
</DIV>
</FORM>
</BODY>
</HTML>
I'd appreciate any help I can get.
Thanks!
CygnusX1