Hello: I need to perform a calculation within a form before submitting it and the code is not working. Please help! I've been looking at this for 3 days! Please see code for OnChange version and 2 (submit) button version below (also included as attached text files). THANKS! OnChange version: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <TITLE>Product Warrantee and Depreciation</TITLE> <LINK REL="StyleSheet" TYPE="text/css" HREF="../sshared/site-style.css"> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin// Date validation function --> function isValidDate(dateStr) { // Checks for the following valid date formats: // MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year var matchArray = dateStr.match(datePat); // is the format ok? if (matchArray == null) { alert(dateStr + " Date is not in a valid format.") return false; } month = matchArray[1]; // parse date into variables day = matchArray[3]; year = matchArray[4]; if (month < 1 || month > 12) { // check month range alert("Month must be between 1 and 12."); return false; } if (day < 1 || day > 31) { alert("Day must be between 1 and 31."); return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert("Month "+month+" doesn't have 31 days!") return false; } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { alert("February " + year + " doesn't have " + day + " days!"); return false; } } return true; } function dateDiff() { date1 = new Date(); date2 = new Date(); diff = new Date(); if (isValidDate(document.Valuation_Form1.PurchaseDate.value)) { // Validates first date date1temp = new Date(document.Valuation_Form1.PurchaseDate.value + " " ); date1.setTime(date1temp.getTime()); } else return false; // otherwise exits if (isValidDate(document.Valuation_Form1.ImpleDate.value)) { // Validates second date date2temp = new Date(document.Valuation_Form1.ImpleDate.value + " "); date2.setTime(date2temp.getTime()); } else return false; // otherwise exits // sets difference date to difference of first date and second date diff.setTime(Math.abs(date1.getTime() - date2.getTime())); timediff = diff.getTime(); weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7)); timediff -= weeks * (1000 * 60 * 60 * 24 * 7); days = Math.floor(timediff / (1000 * 60 * 60 * 24)); timediff -= days * (1000 * 60 * 60 * 24); hours = Math.floor(timediff / (1000 * 60 * 60)); timediff -= hours * (1000 * 60 * 60); mins = Math.floor(timediff / (1000 * 60)); timediff -= mins * (1000 * 60); secs = Math.floor(timediff / 1000); timediff -= secs * 1000; document.Valuation_Form1.difference.value = weeks + " weeks, " + days + " days "; return false; // form should never submit, returns false } function dateDiff2(Valuation_Form1) { date2 = new Date(); date3 = new Date(); diff2 = new Date(); if (isValidDate(document.Valuation_Form1.ImpleDate.value)) { // Validates second date date2temp = new Date(document.Valuation_Form1.ImpleDate.value + " " ); date2.setTime(date2temp.getTime()); } else return false; // otherwise exits if (isValidDate(document.Valuation_Form1.EntryTime.value)) { // Validates third date date3temp = new Date(document.Valuation_Form1.EntryTime.value + " "); date3.setTime(date3temp.getTime()); } else return false; // otherwise exits // sets difference date to difference of second date and third date diff2.setTime(Math.abs(date2.getTime() - date3.getTime())); timediff2 = diff2.getTime(); weeks = Math.floor(timediff2 / (1000 * 60 * 60 * 24 * 7)); timediff2 -= weeks * (1000 * 60 * 60 * 24 * 7); days = Math.floor(timediff2 / (1000 * 60 * 60 * 24)); timediff2 -= days * (1000 * 60 * 60 * 24); hours = Math.floor(timediff2 / (1000 * 60 * 60)); timediff2 -= hours * (1000 * 60 * 60); mins = Math.floor(timediff2 / (1000 * 60)); timediff2 -= mins * (1000 * 60); secs = Math.floor(timediff2 / 1000); timediff2 -= secs * 1000; document.Valuation_Form1.diff2years.value = weeks/52; if (document.Valuation_Form1.diff2years.value > 5) { document.Valuation_Form1.depYear.value = 0; document.Valuation_Form1.diff2years.value = Math.round(document.Valuation_Form1.diff2years.value); } else { document.Valuation_Form1.depYear.value = 5 - Math.round(document.Valuation_Form1.diff2years.value); document.Valuation_Form1.diff2years.value = Math.round(document.Valuation_Form1.diff2years.value); } return false; // form should never submit, returns false } function calculate(){ var depYear = parseFloat(document.Valuation_Form1.depYear.value); var diff2years = parseFloat(document.Valuation_Form1.diff2years.value); var staff = parseFloat(document.Valuation_Form1.AccessoriesCost.value); var equip = parseFloat(document.Valuation_Form1.EquipmentCost.value); var staffequip15 = (staff+equip)/5; var depVal = (staffequip15*depYear); var staffequip = staff+equip; var futureVal = (staffequip * Math.pow((1.04),diff2years))*.5; var futureVal2 = (staffequip * Math.pow((1.04),diff2years))*.75; futureVal = Math.round(futureVal*100.0)/100.0; futureVal2 = Math.round(futureVal2*100.0)/100.0; document.Valuation_Form1.futureVal.value = futureVal; document.Valuation_Form1.futureVal2.value = futureVal2; document.Valuation_Form1.depVal.value = depVal; document.Valuation_Form1.staffequip.value = staffequip; return; } // script end --> </script> </head> <body bgcolor="#FFFFFF" background="../images/Valuationbg.jpg"> <table width="100%" align=left> <tr> <td width="50%"> <H1>Product Warrantee and Depreciation Values</H1> </td> </tr> </table> <p> <br clear="all"> <hr> <!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!-- function Valuation_Form1_Validator(theForm) { if (theForm.EquipmentCost.value.length > 15) { alert("Please enter at most 15 characters in the \"EquipmentCost\" field."); theForm.EquipmentCost.focus(); return (false); } var checkOK = "0123456789-,"; var checkStr = theForm.EquipmentCost.value; var allValid = true; var validGroups = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid) { alert("Please enter only digit characters in the \"EquipmentCost\" field."); theForm.EquipmentCost.focus(); return (false); } if (theForm.AccessoriesCost.value.length > 16) { alert("Please enter at most 16 characters in the \"AccessoriesCost\" field."); theForm.AccessoriesCost.focus(); return (false); } var checkOK = "0123456789-,"; var checkStr = theForm.AccessoriesCost.value; var allValid = true; var validGroups = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid) { alert("Please enter only digit characters in the \"AccessoriesCost\" field."); theForm.AccessoriesCost.focus(); return (false); } if (theForm.MaintCost.value.length > 16) { alert("Please enter at most 16 characters in the \"MaintCost\" field."); theForm.MaintCost.focus(); return (false); } var checkOK = "0123456789-,"; var checkStr = theForm.MaintCost.value; var allValid = true; var validGroups = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid) { alert("Please enter only digit characters in the \"MaintCost\" field."); theForm.MaintCost.focus(); return (false); } return (true); } //--></script><!--webbot BOT="GeneratedScript" endspan --> <FORM METHOD="POST" action="somepage.asp" name="Valuation_Form1" onsubmit="return Valuation_Form1_Validator(this)" language="JavaScript"> <p><b>Date of purchase (MM/DD/YYYY format) PurchaseDate: </b><br> <input type="text" name="PurchaseDate" size="10" tabindex="5" onclick="return Valuation_Form1_Validator(document.Valuation_Form1)"> <INPUT onchange="return Valuation_Form1_Validator(document.Valuation_Form1)"name="PurchaseDate" size="10" maxlength="10" value="<%=Date%>"><br> </p> <p><b>Date product first used (MM/DD/YYYY format) ImpleDate: </b><br> <INPUT onchange="Valuation_Form1_Validator(document.Valuation_Form1)"name="ImpleDate" size="10" maxlength="10" value="<%=Date%>"><br> </p> <p><b>Today's date (MM/DD/YYYY format): </b><br> <INPUT onchange="Valuation_Form1_Validator(document.Valuation_Form1)"type="text" name="EntryTime" size="10" maxlength="10" value="<%=Date%>"><br> </p> <p><b>EquipmentCost:</b><br> $ <!--webbot bot="Validation" i-maximum-length="15" s-data-type="Integer" s-display-name="EquipmentCost" s-number-separators="," --> <INPUT onchange="Valuation_Form1_Validator(document.Valuation_Form1)"name="EquipmentCost" size="10" value="0" maxlength="15"><br> </p> <p><b>AccessoriesCost: </b><br> $ <!--webbot bot="Validation" i-maximum-length="16" s-data-type="Integer" s-display-name="AccessoriesCost" s-number-separators="," --> <INPUT onchange="Valuation_Form1_Validator(document.Valuation_Form1)"name="AccessoriesCost" size="10" value="0" maxlength="16"><br> </p> <p><b>MaintCost:</b><br> $ <!--webbot bot="Validation" i-maximum-length="16" s-data-type="Integer" s-display-name="MaintCost" s-number-separators="," --> <INPUT onchange="Valuation_Form1_Validator(document.Valuation_Form1)"name="MaintCost" size="10" value="0" maxlength="16"><br> </p> <pre><INPUT type="button" name="calc" value="Calculate" onclick="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"> <font face="Arial">(Results are displayed below.)</font><br><hr><h1>Results</h1> <p> diff2years <INPUT onchange="return validNum(document.ofrm)dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"type="text" name="diff2years" size="20" value="0">years. <p> staffequip: $ <INPUT onchange="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"type="text" name="staffequip" size="20" value="0"> <p> depYear: <INPUT onchange="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"type="text" name="depYear" size="20" value="0"> <p> depVal $ <INPUT onchange="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"type="text" name="depVal" size="20" value="0"> <br>(Straight-Line Depreciation Method) <p> futureVal $ <INPUT onchange="return check(event)"type="text" name="futureVal" size="20" value="0"> to $ <INPUT onchange="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"type="text" name="futureVal2" size="20" value="0"> <p> difference <INPUT onchange="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"type=text name=difference value="0 weeks, 0 days" size=35> to develop this system. <br><i>It is also the amount of time buyers could save by purchasing your system. </i><br> </p> </pre> <pre></form> </pre> </body> </pre> <p> </p> </html> 2 (submit) button version: (Input type on "Calculate" button is button, not submit. <HTML> <HEAD> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"> <meta http-equiv="Content-Language" content="en-us"> <TITLE>Product Warrantee and Depreciation</TITLE> <LINK REL="StyleSheet" TYPE="text/css" HREF="../sshared/site-style.css"> <style type="text/css"> </style> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Date validation function --> function isValidDate(dateStr) { // Checks for the following valid date formats: // MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year var matchArray = dateStr.match(datePat); // is the format ok? if (matchArray == null) { alert(dateStr + " Date is not in a valid format.") return false; } month = matchArray[1]; // parse date into variables day = matchArray[3]; year = matchArray[4]; if (month < 1 || month > 12) { // check month range alert("Month must be between 1 and 12."); return false; } if (day < 1 || day > 31) { alert("Day must be between 1 and 31."); return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert("Month "+month+" doesn't have 31 days!") return false; } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { alert("February " + year + " doesn't have " + day + " days!"); return false; } } return true; } function dateDiff(formObj) { date1 = new Date(); date2 = new Date(); diff = new Date(); if (isValidDate(formObj.PurchaseDate.value)) { // Validates first date date1temp = new Date(formObj.PurchaseDate.value + " " ); date1.setTime(date1temp.getTime()); } else return false; // otherwise exits if (isValidDate(formObj.ImpleDate.value)) { // Validates second date date2temp = new Date(formObj.ImpleDate.value + " "); date2.setTime(date2temp.getTime()); } else return false; // otherwise exits // sets difference date to difference of first date and second date diff.setTime(Math.abs(date1.getTime() - date2.getTime())); timediff = diff.getTime(); weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7)); timediff -= weeks * (1000 * 60 * 60 * 24 * 7); days = Math.floor(timediff / (1000 * 60 * 60 * 24)); timediff -= days * (1000 * 60 * 60 * 24); hours = Math.floor(timediff / (1000 * 60 * 60)); timediff -= hours * (1000 * 60 * 60); mins = Math.floor(timediff / (1000 * 60)); timediff -= mins * (1000 * 60); secs = Math.floor(timediff / 1000); timediff -= secs * 1000; formObj.difference.value = weeks + " weeks, " + days + " days "; return false; // form should never submit, returns false } function dateDiff2(formObj) { date2 = new Date(); date3 = new Date(); diff2 = new Date(); if (isValidDate(formObj.ImpleDate.value)) { // Validates second date date2temp = new Date(formObj.ImpleDate.value + " " ); date2.setTime(date2temp.getTime()); } else return false; // otherwise exits if (isValidDate(formObj.EntryTime.value)) { // Validates third date date3temp = new Date(formObj.EntryTime.value + " "); date3.setTime(date3temp.getTime()); } else return false; // otherwise exits // sets difference date to difference of second date and third date diff2.setTime(Math.abs(date2.getTime() - date3.getTime())); timediff2 = diff2.getTime(); weeks = Math.floor(timediff2 / (1000 * 60 * 60 * 24 * 7)); timediff2 -= weeks * (1000 * 60 * 60 * 24 * 7); days = Math.floor(timediff2 / (1000 * 60 * 60 * 24)); timediff2 -= days * (1000 * 60 * 60 * 24); hours = Math.floor(timediff2 / (1000 * 60 * 60)); timediff2 -= hours * (1000 * 60 * 60); mins = Math.floor(timediff2 / (1000 * 60)); timediff2 -= mins * (1000 * 60); secs = Math.floor(timediff2 / 1000); timediff2 -= secs * 1000; formObj.diff2years.value = weeks/52; if (formObj.diff2years.value > 5) { formObj.depYear.value = 0; formObj.diff2years.value = Math.round(formObj.diff2years.value); } else { formObj.depYear.value = 5 - Math.round(formObj.diff2years.value); formObj.diff2years.value = Math.round(formObj.diff2years.value); } return false; // form should never submit, returns false } function calculate(formObj){ var depYear = parseFloat(formObj.depYear.value); var diff2years = parseFloat(formObj.diff2years.value); var staff = parseFloat(formObj.AccessoriesCost.value); var equip = parseFloat(formObj.EquipmentCost.value); var staffequip15 = (staff+equip)/5; var depVal = (staffequip15*depYear); var staffequip = staff+equip; var futureVal = (staffequip * Math.pow((1.04),diff2years))*.5; var futureVal2 = (staffequip * Math.pow((1.04),diff2years))*.75; futureVal = Math.round(futureVal*100.0)/100.0; futureVal2 = Math.round(futureVal2*100.0)/100.0; formObj.futureVal.value = futureVal; formObj.futureVal2.value = futureVal2; formObj.depVal.value = depVal; formObj.staffequip.value = staffequip; return; } // script end --> </script> </HEAD> <BODY> <H1>Product Warrantee and Depreciation Values</H1> <HR> <!--webbot BOT="GeneratedScript" PREVIEW=" " startspan --><script Language="JavaScript" Type="text/javascript"><!-- function Valuation_Form1_Validator(theForm) { if (theForm.ProductName.value == "") { alert("Please enter a value for the \"ProductName\" field."); theForm.ProductName.focus(); return (false); } if (theForm.ProductName.value.length < 2) { alert("Please enter at least 2 characters in the \"ProductName\" field."); theForm.ProductName.focus(); return (false); } if (theForm.ProductName.value.length > 255) { alert("Please enter at most 255 characters in the \"ProductName\" field."); theForm.ProductName.focus(); return (false); } if (theForm.EquipmentCost.value.length > 15) { alert("Please enter at most 15 characters in the \"EquipmentCost\" field."); theForm.EquipmentCost.focus(); return (false); } var checkOK = "0123456789-,"; var checkStr = theForm.EquipmentCost.value; var allValid = true; var validGroups = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid) { alert("Please enter only digit characters in the \"EquipmentCost\" field."); theForm.EquipmentCost.focus(); return (false); } if (theForm.AccessoriesCost.value.length > 16) { alert("Please enter at most 16 characters in the \"AccessoriesCost\" field."); theForm.AccessoriesCost.focus(); return (false); } var checkOK = "0123456789-,"; var checkStr = theForm.AccessoriesCost.value; var allValid = true; var validGroups = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid) { alert("Please enter only digit characters in the \"AccessoriesCost\" field."); theForm.AccessoriesCost.focus(); return (false); } if (theForm.MaintCost.value.length > 16) { alert("Please enter at most 16 characters in the \"MaintCost\" field."); theForm.MaintCost.focus(); return (false); } var checkOK = "0123456789-,"; var checkStr = theForm.MaintCost.value; var allValid = true; var validGroups = true; var decPoints = 0; var allNum = ""; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } if (ch != ",") allNum += ch; } if (!allValid) { alert("Please enter only digit characters in the \"MaintCost\" field."); theForm.MaintCost.focus(); return (false); } if (theForm.price.value.length > 15) { alert("Please enter at most 15 characters in the \"price\" field."); theForm.price.focus(); return (false); } var checkOK = "0123456789-"; var checkStr = theForm.price.value; var allValid = true; var validGroups = true; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } } if (!allValid) { alert("Please enter only digit characters in the \"price\" field."); theForm.price.focus(); return (false); } return (true); } //--></script><!--webbot BOT="GeneratedScript" endspan --> <FORM METHOD="POST" action="somepage.asp" name="Valuation_Form1" onsubmit="return Valuation_Form1_Validator(this)" language="JavaScript"> <INPUT onkeypress="return check(event)"type="hidden" name="EntryTime" value="<%=Date%>"> <TABLE> <TR> <TD ALIGN="right"> <p align="left" style="margin-left: 20"><b> <EM><font size="3">Product Name: </font> </EM></b></TD> <TD> <!--webbot b-value-required="TRUE" bot="Validation" i-maximum-length="255" i-minimum-length="2" s-data-type="String" s-display-name="ProductName" --> <INPUT onkeypress="return check(event)"name="ProductName" size="64" maxlength="255"><b><font size="3"> </font></b></TD> </TR> </TABLE> <P> <BLOCKQUOTE> <div style="border-style: solid; border-width: 1px; padding: 1px 4px"> <br> <b><h1>Calculate the value:</h1></b> <BLOCKQUOTE><p><!-- calculator --> <p> <br clear="all"> <p><b>Date of purchase (MM/DD/YYYY format) PurchaseDate: </b><br> <INPUT onkeypress="return check(event)"name="PurchaseDate" size="10" maxlength="10" value="<%=Date%>"><br> </p> <p><b>Date product first used (MM/DD/YYYY format) ImpleDate: </b><br> <INPUT onkeypress="return check(event)"name="ImpleDate" size="10" maxlength="10" value="<%=Date%>"><br> </p> <p><b>Today's date (MM/DD/YYYY format) EntryTime: </b><br> <INPUT onkeypress="return check(event)"type="text" name="EntryTime" size="10" maxlength="10" value="<%=Date%>"><br> </p> <p><b>EquipmentCost:</b><br> $ <!--webbot bot="Validation" i-maximum-length="15" s-data-type="Integer" s-display-name="EquipmentCost" s-number-separators="," --><INPUT onkeypress="return check(event)"name="EquipmentCost" size="10" value="0" maxlength="15"><br> </p> <p><b>AccessoriesCost: </b><br> $ <!--webbot bot="Validation" i-maximum-length="16" s-data-type="Integer" s-display-name="AccessoriesCost" s-number-separators="," --><INPUT onkeypress="return check(event)"name="AccessoriesCost" size="10" value="0" maxlength="16"><br> </p> <p><b>MaintCost:</b><br> $ <!--webbot bot="Validation" i-maximum-length="16" s-data-type="Integer" s-display-name="MaintCost" s-number-separators="," --><INPUT onkeypress="return check(event)"name="MaintCost" size="10" value="0" maxlength="16"><br> </p> <INPUT onkeypress="return check(event)"type="button" name="calc" value="Calculate" onclick="dateDiff(Valuation_Form1); dateDiff2(Valuation_Form1); calculate(Valuation_Form1); isValidDate(Valuation_Form1);"> <font face="Arial">(Results are displayed below.)</font><br><hr><h2>Results</h1> <p> diff2years <INPUT onkeypress="return check(event)"type="text" name="diff2years" size="20" value="0">years. <p> staffequip: $ <INPUT onkeypress="return check(event)"type="text" name="staffequip" size="20" value="0"> <p> depYear: <INPUT onkeypress="return check(event)"type="text" name="depYear" size="20" value="0"> <p> depVal $ <INPUT onkeypress="return check(event)"type="text" name="depVal" size="20" value="0"> <br>(Straight-Line Depreciation Method) <p> futureVal $ <INPUT onkeypress="return check(event)"type="text" name="futureVal" size="20" value="0"> to $ futureVal2 <INPUT onkeypress="return check(event)"type="text" name="futureVal2" size="20" value="0"> <p> difference <INPUT onkeypress="return check(event)"type="text" name="difference" value="0 weeks, 0 days" size=35> </i><br> </p> <!-- end calculator --> </div> </div> </BLOCKQUOTE> <div><BLOCKQUOTE> <P> Enter the estimated resale price: $ <!--webbot b-allow-digits="TRUE" bot="Validation" i-maximum-length="15" s-data-type="String" --> <INPUT onkeypress="return check(event)"NAME="price" SIZE=15 MAXLENGTH=15 value="0"> <font size="1">(No commas or decimals.)</font><BR> </P> </BLOCKQUOTE></div> </tr> </table> </b> </font> <b> <P> <BR> </P> </BLOCKQUOTE> <INPUT onkeypress="return check(event)"TYPE=submit VALUE="Next" name="Next"> <INPUT onkeypress="return check(event)"type="reset" value="Cancel" name="Cancel" onClick="cancel()"><p> </p> </b> </FORM> </BODY> </HTML>
Jeez. Could you please edit your posting to put CODE-brackets around your code? Look at the menu of the comment-box and find the "insert" button...
POPSICLE, I was looking for some help on this forum, but it looks like most of the recent replies in these threads that I've read are useless comments about how to post the problem and/or offer no good explanations on how to solve the problems.
That's because it's very hard to help if we can't make sense out of what the blue blazes you are even asking -- poorly formatted code, incomplete snippets, broken engrish -- they're all so commonplace there pretty much needs to be a sticky in every coding part of these forums called "How to ask a question"! Now, that said -- your post begs the question: You ARE double-checking the values server-side again right? You know, all user input is suspect and NEVER trust client side processing for values? The unwritten rule of JavaScript -- If you can't make the page work without scripting first, you likely have no business adding scripting to it? Now, that said -- your code is a disastrous mix of HTML 3.2, non-semantic markup, presentational markup, outdated scripting methodologies, language="javascript" on elements that don't even use the language attribute that way, presence of the LONG deprecated language attribute, and Frontpage-style asshattery that to be brutally frank, whatever it is you're expecting that to do -- that's not it... which is why I'd advise throwing that entire train-wreck away and starting over from scratch. Hell, the lack of a doctype and windows-1252 encoding alone should be sending up massive warning flags that said page was NEVER "viable for web deployment" Can I assume you inherited this codebase from someone who never pulled their head out of 1997's rump? Now, that said -- the first thing that should be done is to clean up the form dragging it kicking and screaming into THIS century. <form method="post" action="somepage.asp" id="purchaseForm"> <h1>Product Warrantee and Depreciation Values</h1> <fieldset> <label for="purchaseDate"> Date of purchase (MM/DD/YYYY format): </label><br /> <input type="text" name="PurchaseDate" id="purchaseDate" size="10" maxlength="10" /><br /> <label for="purchaseUsed"> Date product first used (MM/DD/YYYY format) </label><br /> <input type="text" name="ImpleDate" id="purchaseUsed" size="10" maxlength="10" value="<%=Date%>" /><br /> <label for="purchaseToday"> Today's date (MM/DD/YYYY format): </label><br /> <input type="text" name="EntryTime" id="purchaseToday" readonly="readonly" size="10" maxlength="10" value="<%=Date%>" /><br /> <label for="purchaseEquipmentCost"> Equipment Cost: </label><br /> <input type="text" name="EquipmentCost" id="purchaseEquipmentCost" size="10" maxlength="15" value="0" /><br /> <label for="purchaseAccessoriesCost"> Accessories Cost: </label><br /> <input type="text" name="AccessoriesCost" id="purchaseAccessoriesCost" size="10" maxlength="16" value="0" /><br /> <label for="purchaseMaintennanceCost"> Maintennance Cost: </label><br /> <input type="text" name="MaintCost" id="purchaseMaintennanceCost" size="10" maxlength="16" value="0" /> </fieldset> <div class="submitsAndHiddens"> <input type="submit" value="calculate" class="sumbit" /> </div> </form> Code (markup): The next step would be to make it work WITHOUT scripting... showing your results code not as inputs since that's not semantically what it is, but as a TABLE. <table id="purchaseResults"> <caption>Results</caption> <tbody> <tr> <th scope="row">diff2years:</th> <td><span id="result_diff2Years">0</span> years.</td> </tr><tr> <th scope="row">staffequip:</th> <td>$<span id="result_staffequip">0</span></td> </tr><tr> <th scope="row">depYear:</th> <td><span id="result_depYear">0</span></td> </tr><tr> <th scope="row">depVal:</th> <td>$<span id="result_depVal"></span></td> </tr><tr> <th scope="row">futureVal:</th> <td>$ <span id="result_futureVal"></span></td> </tr><tr> <th scope="row">difference:</th> <td> <span id="result_difference">0 weeks, 0 days</span> to develop this system. <br /> <em>It is also the amount of time buyers could save by purchasing your system.</em> </td> </tr> </tbody> </table> Code (markup): Now, once you have it processing it as a normal submit server side (I'd show you how to do that in PHP, but you're working with the pile of manure called ASP that you couldn't pay me to work with) you would then ENHANCE it with your scripting. A GOOD script would hook the markup elements instead of using all that 'onevent' garbage... and even then with the scripting working, NEVER trust it; it's there as a convenience to the user, and anything it makes should NEVER be used server-side if you care about security. Unfortunately your existing script is such a mess, I don't have the time to even TRY to make sense out of what the devil that's even trying to accomplish... I might take a stab at it later though as a diversion.
Here's a cleaned up/working demo: http://www.cutcodedown.com/for_others/wpprod/template.html as with all my examples the directory: http://www.cutcodedown.com/for_others/wpprod/ is unlocked for easy access to the gooey bits and pieces. It would still need a server-side equivalent set of calculations and checks since again, anything calculated client side can't be trusted. In rewriting it I found a lot of problems -- duplicate ID's, attempts to write to elements on the page that don't even exist (like futureVal2), etc, etc... I added some classes to the markup -- v_date and v_price, which I use as triggers for what type of validation/input handling checks should be done. If I have time later I'll write out an explanation of the how/why of the script.
deathshadow, Thank You, Thank You, Thank You! Sorry I hadn't replied sooner, but I spent time studying your code, tweeking it for the application, and wanted to wait to see if I had any questions before I got back to you. Everything worked out well! This form is used as a sort of scratch pad, and the data will not be recorded onto a database. I wrote a huge web application in 2000, when there were not as many server-side options other than ASP. I am updating it to current technology: HTML to current version, CSS to current version, Access to MySQL, FrontPage extensions to Javascript, and ASP to PHP. It surely is made up of a lot of spaghetti code. Unfortunately, I haven't stayed current in the technology so I have a lot to catch up on. I am trying to start up a new company and cannot afford to hire a professional programmer, so I have to do it myself - sweat equity? I won't be ready for the asp to php conversion for another two or three months. Questions: 1. Would you please recommend good books and example resources for learning Javascript and PHP. 2. What development tools IDE's do you use to write and debug your Javascript and PHP code? I work in a PC environment and have Visual Studio 8, TextPad. I also have a Linux Mint system set up, but have never really used it. Thanks again for your wonderful help! It is greatly appreciated!
I got the impression this was some heavy duty legacy code. Cleaning up old stuff is always a challenge. As George would say, a pint of sweat now saves a gallon of blood later. I kind of 'got lucky' on learning PHP as had been programming computers for at least two decades before PHP was a twinkle in Rasmus' eye. To me PHP is just C wearing a frilly dress, and having learned C a decade and a half before PHP even existed, all I've ever taken the time to learn from is the manual itself at php.net! (I actually learned RCA 1802 and Z80 machine language before I learned a higher level language like Basic, Pascal or C). I have difficulty recommending books because I walk into a library or bookseller's these days, I just wander aimlessly through the computer aisle going "user crap... user crap... theory and no application crap..." My advice, just read php.net -- ALL OF IT. I read two pages of PHP.net's documentation of functions and method a night; it's something I just set aside time to do. The comments on function/method pages often have useful snippets better showing how to do things, and I'm always finding functions and object methods I didn't know were even there and new ways of doing things. Once you have the syntax of PHP down, that should be all you really need; why get some third party involved when you can go right to the horse's mouth? As to Javascript, same story really. The only thing I can suggest is going through the JavaScript reference on MDN -- You'll learn a lot more there than anywhere else. I don't use IDE's... most of what they do just gets in my damned way; from second guessing me on how code should work, saying perfectly good code is invalid just because they lag a few versions behind on PHP versions, to goofy garbage I don't even like in my text editors like the illegible acid trip known as colour syntax highlighting, shoving tabs down my throat instead of keeping editor sessions in separate windows, etc, etc... Right now I just use Flo's Notepad 2 for all my development regardless of what language. Doesn't matter if it's x86 assembler, FPC, C++, CC65, PHP, HTML, CSS, JS... That's what I use for editing. It's based on Scintilla while not being a total pile of scite. What I like is that it provides the tools I find useful like a long-line guide, word-wrap markers, brace matching, and proper character set handling, while letting me disable the stuff that annoys me like colour syntax highlighting, tabs, toolbars, etc. Now, you might be wondering "what's wrong with tabs?" -- nothing, in a browser... but for an editor where I might want to have my HTML, CSS, PHP and JS side-by-side in separate windows; that's one of the keys to my workstation is it's a multiple-display machine... on the left and right I have a pair of 24" 1920x1200, and in the center a 27" 2560x1440. Center is an IPS, right is a high end samsung TFT, on the left is an el-cheapo.... and I have that for a reason, so I can see how colors are handled differently across different quality displays. I have my taskbar on the right display in portrait mode, and keep trillian and skype over there too for talking to clients, people I work with and/or help, etc... (I also usually have winamp over there for tunes... need tunes while working to stay sane). On the left display I usually have my editor windows open side-by-side. At 1920 it's more than enough room to see three files at once, even with my large fonts/120dpi setting. WARNING, LARGE Screenshot: http://www.cutcodedown.com/images/desktop2014.jpg 920 megs, 6400x1440 Really though, any flat text editor you're comfortable with should be all you need -- EditPlus, Notepad++, gEdit, Text Wrangler, Win32pad, they're all fine editors that are MORE than robust enough for building a website or working with any other programming task. Generally IDE's are just bloated crap, and sooner or later it helps to take the training wheels off and put on the big boy pants. For testing I test in the actual browsers through a local XAMPP setup... so I'm actually using Apache, PHP and mySQL just like my server does. I also have virtualBox installed so I can test actual IE 5 and 6 in their native environments (98 and XP) though I really don't test those as much as I used to. I also have Debian installed for testing the differences in font rendering caused by the steaming pile known as freetype, and a OSX install for Safari and the fact that Firefox behaves differently on Mac than Win/Lin. On the OSX install in VirtualBox I also have xCode installed as it includes an iPod/iPad/IPhone emulator. Since if you care about visitors actually being able to use your stuff, it's all about testing.
Thanks for your additional recommendations. I'm pretty home bound right now, and don't have techs to compare notes with anymore.