Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Get an Error I don't recognize?

Get an Error I don't recognize?

JVRudnick
11-22-2004, 06:36 PM
Hello all...
got a new javascipt running on my form page, whereby a user can simply click to make some data COPY to new fields....much like those "Click here to make the Shipping Address the same as the Billing Address" style forms you use online.

Thing, is it works fine when I click (in the Vehicle Pickup Cell area) to get the data to copy to the new fields, but when I then try to un-check that checkbox, I get an error that says "txtCoName is undefined" and it points at the line with the <<<< below.

??? Undefined? what does that mean? I've got Option Explict turned off in this ASP page....

page code is here.......sorry about the length but I've cut it drastically...
======================================================
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var CompanyName = "";
var CompanyAddress = "";
var CompanyCity = "";
var CompanyState = "";
var CompanyZip = "";
var ContactName = "";
var CompanyPhone = "";
var CompanyFax = "";
var CompanyEmail = "";


function InitSaveVariables(form) {
CompanyName = form.txtCoName.value;
CompanyAddress = form.txtCoAddress.value;
CompanyCity = form.txtCoCity.value;
CompanyState = form.CoState.value;
CompanyZip = form.txtCoZip.value;
ContactName = form.txtCoContactName.value;
CompanyPhone = form.txtCoPhone.value;
CompanyFax = form.txtCoFax.value;
CompanyEmail = form.txtCoEmail.value;
}

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.txtVehName.value = form.txtCoName.value;
form.txtVehAddress.value = form.txtCoAddress.value;
form.txtVehCity.value = form.txtCoCity.value;
form.VehState.value = form.CoState.value;
form.txtVehZip.value = form.txtCoZip.value;
form.txtVehContactName.value = form.txtCoContactName.value;
form. txtVehPhone.value = form.txtCoPhone.value;
form.txtVehFax.value = form.txtCoFax.value;
form.txtVehEmail.value = form.txtCoEmail.value;
}
else {
form.txtCoName.value = txtCoName; //<<<<<<<<<<<< ERROR POINTS HERE
form.txtCoAddress.value = txtCoAddress;
form.txtCoCity.value = txtCoCity;
form.CoState.value = CoState;
form.txtCoZip.value = txtCoZip;
form.txtCoContactName = txtCoContactName;
form.txtCoPhone = txtCoPhone;
form.txtCoFax = txtCoFax;
form.txtCoEmail = txtCoEmail;

}
}
// End -->
</script>


</head>

<body topmargin="0" leftmargin="0">

<div id="container">

<!------------------------------------------------------------------------------------------------------------------->
<!-- FORM HERE TO GO TO sendorder.ASP------------------------------------------------------------->
<form name="orderSingle" method="post" action="sendOrderSingle.asp">
<!------------------------------------------------------------------------------------------------------------------->
<!------------------------------------------------------------------------------------------------------------------->

<!-- WELCOME CONTENTS HERE ---------------------------------------------------------------------------------------------------------->
<DIV style="position:absolute;left:0;top:10;width:850;height:420;z-index:14;visibility:visible;">
<br>





<!-- CUSTOMER INFO----------------------------------------------------------------------------------->
<!-- HEADERS -->
<table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<td>

<table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#a1a1a1">
<tr bgcolor="#a1a1a1">
<td>
<tr bgcolor=#183DA8>
<td colspan=3><font size="3" face="Verdana" color="white"><b>&nbsp;&nbsp;Customer Information :
</td>
</tr>
<tr>
<td><font size="2" face="Verdana" color="black"><b>Company Name :</b> <input type="text" name="txtCoName" size="30"></td>
<td><font size="2" face="Verdana" color="black"><b>Address :</b> <input type="text" name="txtCoAddress" size="30"></td>
<td><font size="2" face="Verdana" color="black"><b>City : </b><input type="text" name="txtCoCity" size="20"></td>
</tr>
<tr>
<td>
<font size="2" face="Verdana" color="black"> <b>State or Province...</b>
</td>
<td nowrap colspan=2>
<SELECT size=1 name="CoState">
<OPTION selected>Choose a Province or State...
<option value="Alberta">Alberta</option>
<option value="British Columbia">British Columbia</option>
<option value="Manitoba">Manitoba</option>
<option value="New Brunswick">New Brunswick</option>
<option value="Newfoundland">Newfoundland</option>
<option value="North West Terrorties">North West Terrorties</option>
<option value="Nova Scotia">Nova Scotia</option>
<option value="Ontario">Ontario</option>
<option value="Prince Edward Island">Prince Edward Island</option>
<option value="Quebec">Quebec</option>
<option value="Saskatchewan">Saskatchewan</option>
</SELECT>
</td>
</tr>
<tr>
<td><font size="2" face="Verdana" color="black"><b>Zip/Postal Code :</b> <br><input type="text" name="txtCoZip" size="12"></td>
<td><font size="2" face="Verdana" color="black"><b>Contact Name : </b><br><input type="text" name="txtCoContactName" size="30"></td>
<td><font size="2" face="Verdana" color="black"><b>Phone # : </b><br><input type="text" name="txtCoPhone" size="20"></td>
</tr>

<tr>
<td><font size="2" face="Verdana" color="black"><b>Fax :</b> <br><input type="text" name="txtCoFax" size="12"></td>
<td><font size="2" face="Verdana" color="black"><b>Email :</b> <br><input type="text" name="txtCoEmail" size="30"></td>
</tr>
</td></tr>
</table>
</td></tr>
<table>


<!-- VEHICLE PICKUP----------------------------------------------------------------------------------->
<!-- HEADERS -->
<table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<td>

<table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#cccccc">
<tr bgcolor="#a1a1a1">

<tr bgcolor=#183DA8>
<Td colspan=3><font size="3" face="Verdana" color="white"><b>&nbsp;&nbsp;<b>Vehicle Pickup Information :
<font size="1" face="Verdana" color="white">

<!-- **************************************************************************************************************************************************************************** -->
Click here if the information here is the same as in the Customer information section
<input type="checkbox" name="copy" OnClick="javascript:ShipToBillPerson(this.form);" value="checkbox">

</font>
</td>
</tr>

<tr>
<td><font size="2" face="Verdana" color="black"><b>Company Name :</b> <input type="text" name="txtVehName" size="30"></td>
<td><font size="2" face="Verdana" color="black"><b>Address :</b> <input type="text" name="txtVehAddress" size="30"></td>
<td><font size="2" face="Verdana" color="black"><b>City : </b><input type="text" name="txtVehCity" size="20"></td>
</tr>
<tr>
<td>
<font size="2" face="Verdana" color="black"> <b>Choose your State or Province...</b>
</td>
<td nowrap colspan=2>
<SELECT size=1 name="VehState">
<OPTION selected>Choose a Province or State...
<option value="Alberta">Alberta</option>
<option value="British Columbia">British Columbia</option>
<option value="Manitoba">Manitoba</option>
<option value="New Brunswick">New Brunswick</option>
<option value="Newfoundland">Newfoundland</option>
<option value="North West Terrorties">North West Terrorties</option>
<option value="Nova Scotia">Nova Scotia</option>
<option value="Ontario">Ontario</option>
<option value="Prince Edward Island">Prince Edward Island</option>
<option value="Quebec">Quebec</option>
<option value="Saskatchewan">Saskatchewan</option>
</SELECT>
</td>
</tr>
<tr>
<td><font size="2" face="Verdana" color="black"><b>Zip/Postal Code :</b> <br><input type="text" name="txtVehZip" size="12"></td>
<td><font size="2" face="Verdana" color="black"><b>Contact Name : </b><br><input type="text" name="txtVehContactName" size="30"></td>
<td><font size="2" face="Verdana" color="black"><b>Phone # : </b><br><input type="text" name="txtVehPhone" size="20"></td>
</tr>
<tr>
<td><font size="2" face="Verdana" color="black"><b>Fax :</b> <br><input type="text" name="txtVehFax" size="12"></td>
<td><font size="2" face="Verdana" color="black"><b>Email :</b> <br><input type="text" name="txtVehEmail" size="30"></td>
</tr>
</td></tr>
</table>
</td></tr>
<table>
</form>
</body>
</html>
==========================================

Anyone tell me what that error refers to?

Jim

Puffin the Erb
11-22-2004, 07:02 PM
That's because 'txtCoName' or any of the other variables below it such as 'txtCoAddress' don't exist anywhere in your code.

What do you want the 'else' section to do?

JVRudnick
11-22-2004, 07:07 PM
just caught that myownself. what I need to happen, is if the user clicks the checkbox, then all content in the Customer info area, gets copied to the Vehicle Pickup area.

and if they then uncheck that same box, all of that 'copied' data in the Vehicle Pickup area gets removed and the fields are all empty.

I realize now, in looking much closer the problem lies with my ELSE area, in that I'm somehow not setting the Vehicle Pickup items to BLANKS....

???

Jim

Willy Duitt
11-22-2004, 07:09 PM
And if it didn't error out there it would error out on the next line and the line after that...

Is txtCoName a variable (which is undeclared anywhere in the code you provided) or an input name?

If the latter you need to declare the document.form reference and what attribute of the input you are targetting... I would guess the value....


form.txtCoName.value = form.txtCoName.value;

But then again, in the above context... The entire else conditional is redundant and unneeded....

.....Willy

Willy Duitt
11-22-2004, 07:12 PM
just caught that myownself. what I need to happen, is if the user clicks the checkbox, then all content in the Customer info area, gets copied to the Vehicle Pickup area.

and if they then uncheck that same box, all of that 'copied' data in the Vehicle Pickup area gets removed and the fields are all empty.

I realize now, in looking much closer the problem lies with my ELSE area, in that I'm somehow not setting the Vehicle Pickup items to BLANKS....

???

Jim

In that case: form.txtCoName.value = ''

Puffin the Erb
11-22-2004, 07:15 PM
You could do :

else {
for(var i=10;i<form.length;i++)
{
form.elements[i].value="";
}
}

The first element in the second section of the form can be addressed as index position 10 of the whole form using the elements array and then just loop to the end of the elements array.

JVRudnick
11-22-2004, 07:23 PM
but that syntax gets me an error (REALLY new to javascript !!!)

here's what I'm using now....
=======================================================
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var CompanyName = "";
var CompanyAddress = "";
var CompanyCity = "";
var CompanyStateIndex = 0;
var CompanyZip = "";
var ContactName = "";
var CompanyPhone = "";
var CompanyFax = "";
var CompanyEmail = "";


function InitSaveVariables(form) {
CompanyName = form.txtCoName.value;
CompanyAddress = form.txtCoAddress.value;
CompanyCity = form.txtCoCity.value;
CompanyState = form.CoState.selectedIndex;
CompanyZip = form.txtCoZip.value;
ContactName = form.txtCoContactName.value;
CompanyPhone = form.txtCoPhone.value;
CompanyFax = form.txtCoFax.value;
CompanyEmail = form.txtCoEmail.value;
}

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.txtVehName.value = form.txtCoName.value;
form.txtVehAddress.value = form.txtCoAddress.value;
form.txtVehCity.value = form.txtCoCity.value;
form.VehState.value = form.CoState.selectedIndex;
form.txtVehZip.value = form.txtCoZip.value;
form.txtVehContactName.value = form.txtCoContactName.value;
form. txtVehPhone.value = form.txtCoPhone.value;
form.txtVehFax.value = form.txtCoFax.value;
form.txtVehEmail.value = form.txtCoEmail.value;
}

}
// End -->
</script>
===============================================

What I want to do is to add that new ELSE to the function, that will
set ALL vars in the Vehicle Pickup area back to BLANKS.

Your " at the end of the line didnt' work, nor did ";

???


Jim

Puffin the Erb
11-22-2004, 07:28 PM
I only posted the else.
Here's the full function.

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.txtVehName.value = form.txtCoName.value;
form.txtVehAddress.value = form.txtCoAddress.value;
form.txtVehCity.value = form.txtCoCity.value;
form.VehState.value = form.CoState.value;
form.txtVehZip.value = form.txtCoZip.value;
form.txtVehContactName.value = form.txtCoContactName.value;
form. txtVehPhone.value = form.txtCoPhone.value;
form.txtVehFax.value = form.txtCoFax.value;
form.txtVehEmail.value = form.txtCoEmail.value;
}
else {
for(var i=10;i<form.length;i++)
{
form.elements[i].value=""; //double quotes x 2
}
}
}

JVRudnick
11-22-2004, 07:34 PM
nicely done. Now, I'm going to try to do the same thing for the last area I also have to offer up to the user if they wish to copy same...


DONE! Thanks fellas....


:-)

Jim

JVRudnick
11-22-2004, 08:06 PM
Lo again...

The script which now works perfectly, has a "side effect" that I just found.

When I fill in the user data, then click the COPY checkbox, it does so quite nicely. But as soon as I UNCLICK the COPY checkbox -- this action "crushes" my SUBMIT and RESET buttons to almost nothing...

???

How can that be? ie the buttons way down the page are being shrunken horizontally by 90%

???

jim

Willy Duitt
11-22-2004, 08:22 PM
Lo again...

The script which now works perfectly, has a "side effect" that I just found.

When I fill in the user data, then click the COPY checkbox, it does so quite nicely. But as soon as I UNCLICK the COPY checkbox -- this action "crushes" my SUBMIT and RESET buttons to almost nothing...

???

How can that be? ie the buttons way down the page are being shrunken horizontally by 90%

???

jim

Chances are the for loop is removing the submit and reset button text which are their value and making those blank as well... :eek:

Puffin the Erb
11-22-2004, 09:01 PM
Willy's right, you didn't have those form elements (submit and reset) in your original code.
The loop is going to the end of the elements array and setting the values of these buttons to nothing. Buttons are sized according to the text label specified by the value attribute so if the value attribute has no value then the buttons will shrink.
There are various ways to fix this. Either stop the loop at the correct point ( before your buttons) or test for the element type before setting its value.:

function ShipToBillPerson(form) {
if (form.copy.checked) {
InitSaveVariables(form);
form.txtVehName.value = form.txtCoName.value;
form.txtVehAddress.value = form.txtCoAddress.value;
form.txtVehCity.value = form.txtCoCity.value;
form.VehState.value = form.CoState.value;
form.txtVehZip.value = form.txtCoZip.value;
form.txtVehContactName.value = form.txtCoContactName.value;
form. txtVehPhone.value = form.txtCoPhone.value;
form.txtVehFax.value = form.txtCoFax.value;
form.txtVehEmail.value = form.txtCoEmail.value;
}
else {
for(var i=10;i<form.length;i++)
{
if(form.elements[i].type!="submit"&&form.elements[i].type!="reset")
{
form.elements[i].value=""; //double quotes x 2
}
}
}
}

JVRudnick
11-22-2004, 09:02 PM
very logical.

IS there a way to STOP the loop before it gets to those buttons?

IE I see a [i] that is being counted....how do I stop same before the SEND button?

Jim

JVRudnick
11-22-2004, 09:06 PM
thanks Puffin....will try it right now...

:-)

Jim

JVRudnick
11-22-2004, 09:16 PM
thanks Puffin...works great!

:-)

Jim


 

TOP

For more info

setting a minimum size
Auto Preview of Image 
Refresh with a query s
JS Validation obsolete
Javascript Pop up func
Slide show transitions
I'm a newbie...please!
how to write coding in
Advanced Debug Info 
.js file doesn't work 

News Archive

Adding Graphic To Text
re-direct form after s
pop up window controls
Clock on homepage - He
passing a param from a
Password Procection wi
document.title in same
focus onload 
Counting Wrong from Ri
Help needed on how to 

Related stories:

Drag n drop Thumbnail Images to iFrame, with Original Size
Help with an online order form using drop down boxes
Check to see if a page exists in Javascript.
variable scope
absolutely positioned scrollable area code wont work for me...
multiple slideshows on one page with linkable pics?
Math

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics