Javascript Errors by newbie

D

David Rad

After an exhaustive search on user groups/web I make a humble request
for HELP! The script below is contained in
http://shop.rsci.com/edit5.html. I get errors pointing to line 135 and
186. There are no duplicate functions that I can determine. Can anyone
point me in the right direction? Thanks, David.


<SCRIPT language=javascript><!--

function PlaceInShoppingCart(){
var strUrl, strUrl2, lngAvail, lngOrdered, strMessage, strMessage2,
strMessage3, strReturn, strValue, strType, strWebItemStatus,
strOrderQty;
var blFlag = new Boolean(true);
blFlag = true;
strType = " ";
strValue = "0";
strWebItemStatus = " ";
//alert("WebITemStatus" + strWebItemStatus)
if ( ( strValue == "0" ) || isNaN( strValue ) ) {
strValue = 1;
}
else {
strValue = parseInt( strValue);
}
// COMMENTED OUT THE LOGIC FOR M IMTYPE ITEMS
//if( ( strValue ) > 1 & strType == 'M' ){
// lngAvail = parseFloat(document.frmItemInfo.AvailableUnits.value);
// strOrderQty = parseInt(document.frmItemInfo.Quantity.value);
// leave commented out// alert("strOrderQty=" + strOrderQty)
// leave commented out// alert("lngAvail=" + lngAvail +
"document.frmItemInfo.Quantity.value + lngAvail" +
(parseInt(document.frmItemInfo.Quantity.value) + lngAvail))
// leave commented out// alert("Quantity=" +
document.frmItemInfo.Quantity.value)
// leave commented out// if( ( document.frmItemInfo.Quantity.value %
strValue ) != 0 ){
// leave commented out// if( ( document.frmItemInfo.Quantity.value %
strValue ) != 0 && (parseInt(document.frmItemInfo.Quantity.value)) >
parseInt(lngAvail)) {
// if( ( document.frmItemInfo.Quantity.value % strValue ) != 0 && ((
strOrderQty + lngAvail) % strValue) != 0 &&
(document.frmItemInfo.Quantity.value > lngAvail)) {
// alert("The amount that you have requested is not a multiple of the
Standard Package Quantity");
// blFlag = false;
// }
//}

if ( ( blFlag ) && ( document.frmItemInfo.ItemDesc.value != "Item Not
Found, Did you select the appropriate search?" ) ) {
strUrl = "richmondshoppingcartmiddle.asp";
strUrl2 = "search_results_industrial.asp";
lngAvail = parseFloat(document.frmItemInfo.AvailableUnits.value);
lngOrdered = parseFloat(document.frmItemInfo.Quantity.value);

// alert(lngOrdered > lngAvail);
strReturn = "\r\n";
strMessage = "We currently have a quantity of " + lngAvail + "
available." + strReturn + "Click OK to order your requested quantity."
+ strReturn + "Click Cancel to change your order quantity." +
strReturn;
strMessage2 = "We currently have none available." + strReturn +
"Click OK to Backorder your requested quantity of " + lngOrdered +
"." + strReturn + "Click Cancel to remove this line item from the
order."
strMessage3 = "We currently have a remaining quantity of " + lngAvail
+ " available." + strReturn + "Click OK to order the remaining
quantity." + strReturn + "Click Cancel to change your order quantity."
+ strReturn;
if( lngOrdered > lngAvail && strWebItemStatus == "D") {
if( window.confirm(strMessage3) ){
Quantity = lngAvail
document.forms[0].func.value = "add"
document.frmItemInfo.action = strUrl;
document.frmItemInfo.submit();
}
}
else
//if( lngOrdered > lngAvail ) {
//alert("1")
// if( window.confirm(strMessage) ){
// document.forms[0].func.value = "add"
// document.frmItemInfo.action = strUrl;
// document.frmItemInfo.submit();
//}
//}
//else
{
//alert("2")
document.forms[0].func.value = "add"
document.frmItemInfo.action = strUrl;
document.frmItemInfo.submit();
}

}
}

/*
function PlaceInShoppingCart(){
var strUrl, strUrl2, lngAvail, lngOrdered, strMessage, strMessage2,
strReturn;
strUrl = "richmondshoppingcartmiddle.asp";
strUrl2 = "search_results_industrial.asp";
lngAvail = document.frmItemInfo.AvailableUnits.value;
lngOrdered = document.frmItemInfo.Quantity.value;
strReturn = "\r\n";
strMessage = "We currently have a quantity of " + lngAvail + "
available." + strReturn + "Click OK to order your requested quantity."
+ strReturn + "Click Cancel change your order quantity.";
strMessage2 = "We currently have none available." + strReturn +
"Click OK to Backorder your requested quantity of " + lngOrdered +
"." + strReturn + "Click Cancel to remove this line item from the
order."
if( (!isNaN(document.frmItemInfo.Quantity.value ) ) &&
(document.frmItemInfo.Quantity.value > 0) ){
if ( lngAvail < 1 )
if ( window.confirm(strMessage2) )
{
document.frmItemInfo.Quantity.value = lngOrdered
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit(); }
else {
//document.frmItemInfo.Quantity.value = 1
//document.forms[0].action = strUrl2;
//document.forms[0].submit()

}

else
if ( ( lngOrdered > lngAvail ) && (
document.frmItemInfo.cbBackOrder.checked) )
{
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit();
}
else
if ( lngOrdered > lngAvail && ( window.confirm(strMessage) ) )
{
document.frmItemInfo.Quantity.value = lngOrdered
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit();
}
else
if ( ( lngOrdered <= lngAvail ) )
{
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit()
}
}
else
alert("The quantity ordered must be a number and greater than 0.")
}
*/
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--
function GetCheckedValue( strRB ){
var strTemp, i;
i = 0;
while (i < strRB.length ) {
if ( strRB.checked )
strTemp = strRB.value;
i++;
}
return strTemp;
}

function SetDropDownSelected( objddlb, strValue ){
var i;

for( i = 0; i < objddlb.length; i++ ){
if ( objddlb.value == strValue ){
objddlb.selected = true
}
}
}
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--

function PerformSearch() {
var strQS;
strQS = "rdZS=" + GetCheckedValue(document.forms[0].rdZS);
strQS += "&ZipSearch=" + document.forms[0].ZipSearch.value;
// alert(document.forms[0].cbExactMatch.checked == true);
//if (document.forms[0].cbExactMatch.checked == true){
//alert("checked")
strQS += "&ExactMatch=1"
//}
//else{
//alert("not checked")
// strQS += "&ExactMatch=0"
//}
//alert("richmondSearchIntermediate.asp?" + strQS)
top.location = "ZipSearch_Lookup.asp?" + strQS;
}

function DoNothing() {

}

function selectItems() {
var strQS;
strQS += "&ZipSearch=" + ""
// Do Not use the ZipSearch input box value when searching by Item
Search Word. Set it to BLANKS
//strQS += "&ZipSearch=" + document.forms[0].ZipSearch.value;

//alert(document.forms[0].cbExactMatch.checked == true);
if (document.forms[0].cbExactMatch.checked == true){
//alert("checked")
strQS += "&ExactMatch=1"
}
else{
//alert("not checked")
strQS += "&ExactMatch=0"
}
//alert("richmondSearchIntermediate.asp?" + strQS)
top.location = "ZipSearch_Lookup.asp?" + strQS;
}
// function selectItems() {
// var strQS;
// strQS += "&ZipSearch=" + document.forms[0].ZipSearch.value;
// strQS += "&ZipSearch=" + "#";

// alert(document.forms[0].cbExactMatch.checked == true);
// if (document.forms[0].cbExactMatch.checked == true){
// alert("checked")
// strQS += "&ExactMatch=1"
// }
// else{
// alert("not checked")
// strQS += "&ExactMatch=0";
// }
// alert("BurcoSearchIntermediate.asp?" + strQS)
// top.location = "RichmondZipSearchLookup.asp?" + strQS;
// }
//-->
</SCRIPT>
 
K

kaeli

After an exhaustive search on user groups/web I make a humble request
for HELP! The script below is contained in
http://shop.rsci.com/edit5.html. I get errors pointing to line 135 and
186. There are no duplicate functions that I can determine. Can anyone
point me in the right direction? Thanks, David.

Since you're a newbie, I won't be my usual mean-ass self. ;)

If you have code problems, post the error message you receive (if any)
and a SMALL snippet of fully functional code that we can copy and paste
into a document and see the problem. Showing us a huge script and we
don't know what you expect from it makes it really hard to help you.
What was all that code supposed to DO? What did it do instead?

That said...
I get no errors immediately when I visit your page (netscape or IE).
What action should I take to replicate the error you received?

--
 
L

Lee

David Rad said:
After an exhaustive search on user groups/web I make a humble request
for HELP! The script below is contained in
http://shop.rsci.com/edit5.html. I get errors pointing to line 135 and
186. There are no duplicate functions that I can determine. Can anyone
point me in the right direction? Thanks, David.

I don't get any error messages when the page loads
or when I click "add to cart".

What do you have to do to get the error messages?
What is the exact text of the error messages?
What browser are you using?
Which lines does your browser consider to be 135 and 186?
 
T

Tia

David Rad said:
After an exhaustive search on user groups/web I make a humble request
for HELP! The script below is contained in
http://shop.rsci.com/edit5.html. I get errors pointing to line 135 and
186. There are no duplicate functions that I can determine. Can anyone
point me in the right direction? Thanks, David.


<SCRIPT language=javascript><!--

function PlaceInShoppingCart(){
var strUrl, strUrl2, lngAvail, lngOrdered, strMessage, strMessage2,
strMessage3, strReturn, strValue, strType, strWebItemStatus,
strOrderQty;
var blFlag = new Boolean(true);
blFlag = true;
strType = " ";
strValue = "0";
strWebItemStatus = " ";
//alert("WebITemStatus" + strWebItemStatus)
if ( ( strValue == "0" ) || isNaN( strValue ) ) {
strValue = 1;
}
else {
strValue = parseInt( strValue);
}
// COMMENTED OUT THE LOGIC FOR M IMTYPE ITEMS
//if( ( strValue ) > 1 & strType == 'M' ){
// lngAvail = parseFloat(document.frmItemInfo.AvailableUnits.value);
// strOrderQty = parseInt(document.frmItemInfo.Quantity.value);
// leave commented out// alert("strOrderQty=" + strOrderQty)
// leave commented out// alert("lngAvail=" + lngAvail +
"document.frmItemInfo.Quantity.value + lngAvail" +
(parseInt(document.frmItemInfo.Quantity.value) + lngAvail))
// leave commented out// alert("Quantity=" +
document.frmItemInfo.Quantity.value)
// leave commented out// if( ( document.frmItemInfo.Quantity.value %
strValue ) != 0 ){
// leave commented out// if( ( document.frmItemInfo.Quantity.value %
strValue ) != 0 && (parseInt(document.frmItemInfo.Quantity.value)) >
parseInt(lngAvail)) {
// if( ( document.frmItemInfo.Quantity.value % strValue ) != 0 && ((
strOrderQty + lngAvail) % strValue) != 0 &&
(document.frmItemInfo.Quantity.value > lngAvail)) {
// alert("The amount that you have requested is not a multiple of the
Standard Package Quantity");
// blFlag = false;
// }
//}

if ( ( blFlag ) && ( document.frmItemInfo.ItemDesc.value != "Item Not
Found, Did you select the appropriate search?" ) ) {
strUrl = "richmondshoppingcartmiddle.asp";
strUrl2 = "search_results_industrial.asp";
lngAvail = parseFloat(document.frmItemInfo.AvailableUnits.value);
lngOrdered = parseFloat(document.frmItemInfo.Quantity.value);

// alert(lngOrdered > lngAvail);
strReturn = "\r\n";
strMessage = "We currently have a quantity of " + lngAvail + "
available." + strReturn + "Click OK to order your requested quantity."
+ strReturn + "Click Cancel to change your order quantity." +
strReturn;
strMessage2 = "We currently have none available." + strReturn +
"Click OK to Backorder your requested quantity of " + lngOrdered +
"." + strReturn + "Click Cancel to remove this line item from the
order."
strMessage3 = "We currently have a remaining quantity of " + lngAvail
+ " available." + strReturn + "Click OK to order the remaining
quantity." + strReturn + "Click Cancel to change your order quantity."
+ strReturn;
if( lngOrdered > lngAvail && strWebItemStatus == "D") {
if( window.confirm(strMessage3) ){
Quantity = lngAvail
document.forms[0].func.value = "add"
document.frmItemInfo.action = strUrl;
document.frmItemInfo.submit();
}
}
else
//if( lngOrdered > lngAvail ) {
//alert("1")
// if( window.confirm(strMessage) ){
// document.forms[0].func.value = "add"
// document.frmItemInfo.action = strUrl;
// document.frmItemInfo.submit();
//}
//}
//else
{
//alert("2")
document.forms[0].func.value = "add"
document.frmItemInfo.action = strUrl;
document.frmItemInfo.submit();
}

}
}

/*
function PlaceInShoppingCart(){
var strUrl, strUrl2, lngAvail, lngOrdered, strMessage, strMessage2,
strReturn;
strUrl = "richmondshoppingcartmiddle.asp";
strUrl2 = "search_results_industrial.asp";
lngAvail = document.frmItemInfo.AvailableUnits.value;
lngOrdered = document.frmItemInfo.Quantity.value;
strReturn = "\r\n";
strMessage = "We currently have a quantity of " + lngAvail + "
available." + strReturn + "Click OK to order your requested quantity."
+ strReturn + "Click Cancel change your order quantity.";
strMessage2 = "We currently have none available." + strReturn +
"Click OK to Backorder your requested quantity of " + lngOrdered +
"." + strReturn + "Click Cancel to remove this line item from the
order."
if( (!isNaN(document.frmItemInfo.Quantity.value ) ) &&
(document.frmItemInfo.Quantity.value > 0) ){
if ( lngAvail < 1 )
if ( window.confirm(strMessage2) )
{
document.frmItemInfo.Quantity.value = lngOrdered
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit(); }
else {
//document.frmItemInfo.Quantity.value = 1
//document.forms[0].action = strUrl2;
//document.forms[0].submit()

}

else
if ( ( lngOrdered > lngAvail ) && (
document.frmItemInfo.cbBackOrder.checked) )
{
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit();
}
else
if ( lngOrdered > lngAvail && ( window.confirm(strMessage) ) )
{
document.frmItemInfo.Quantity.value = lngOrdered
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit();
}
else
if ( ( lngOrdered <= lngAvail ) )
{
document.forms[0].func.value = "add"
document.forms[0].action = strUrl;
document.forms[0].submit()
}
}
else
alert("The quantity ordered must be a number and greater than 0.")
}
*/
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--
function GetCheckedValue( strRB ){
var strTemp, i;
i = 0;
while (i < strRB.length ) {
if ( strRB.checked )
strTemp = strRB.value;
i++;
}
return strTemp;
}

function SetDropDownSelected( objddlb, strValue ){
var i;

for( i = 0; i < objddlb.length; i++ ){
if ( objddlb.value == strValue ){
objddlb.selected = true
}
}
}
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--

function PerformSearch() {
var strQS;
strQS = "rdZS=" + GetCheckedValue(document.forms[0].rdZS);
strQS += "&ZipSearch=" + document.forms[0].ZipSearch.value;
// alert(document.forms[0].cbExactMatch.checked == true);
//if (document.forms[0].cbExactMatch.checked == true){
//alert("checked")
strQS += "&ExactMatch=1"
//}
//else{
//alert("not checked")
// strQS += "&ExactMatch=0"
//}
//alert("richmondSearchIntermediate.asp?" + strQS)
top.location = "ZipSearch_Lookup.asp?" + strQS;
}

function DoNothing() {

}

function selectItems() {
var strQS;
strQS += "&ZipSearch=" + ""
// Do Not use the ZipSearch input box value when searching by Item
Search Word. Set it to BLANKS
//strQS += "&ZipSearch=" + document.forms[0].ZipSearch.value;

//alert(document.forms[0].cbExactMatch.checked == true);
if (document.forms[0].cbExactMatch.checked == true){
//alert("checked")
strQS += "&ExactMatch=1"
}
else{
//alert("not checked")
strQS += "&ExactMatch=0"
}
//alert("richmondSearchIntermediate.asp?" + strQS)
top.location = "ZipSearch_Lookup.asp?" + strQS;
}
// function selectItems() {
// var strQS;
// strQS += "&ZipSearch=" + document.forms[0].ZipSearch.value;
// strQS += "&ZipSearch=" + "#";

// alert(document.forms[0].cbExactMatch.checked == true);
// if (document.forms[0].cbExactMatch.checked == true){
// alert("checked")
// strQS += "&ExactMatch=1"
// }
// else{
// alert("not checked")
// strQS += "&ExactMatch=0";
// }
// alert("BurcoSearchIntermediate.asp?" + strQS)
// top.location = "RichmondZipSearchLookup.asp?" + strQS;
// }
//-->
</SCRIPT>



I was able to get the error by searching by an item in the drop down. Here
they are using Firefox Javascript console. :

Error: document.forms[0].cbExactMatch has no properties
Source File: http://shop.rsci.com/edit5.html
Line: 187

by viewing the source, I see the element cbExactMatch is defined as:

<INPUT type="hidden" name="cbExactMatch">

thus, it has no properties


Error: strRB has no properties
Source File: http://shop.rsci.com/edit5.html
Line: 136

looks like the element passed into GetCheckedValue has no properties when
this line is executed:

if ( strRB.checked )


Tia
 
L

Lee

Tia said:


Please don't quote the entire original post.
It was too long to begin with.

I was able to get the error by searching by an item in the drop down. Here
they are using Firefox Javascript console. :

Error: document.forms[0].cbExactMatch has no properties
Source File: http://shop.rsci.com/edit5.html
Line: 187

by viewing the source, I see the element cbExactMatch is defined as:

<INPUT type="hidden" name="cbExactMatch">

thus, it has no properties


It has "type" and "name" and "value" properties, among others.
The real problem is that it's contained in the second form on
the page, and so it's not found in forms[0].

Error: strRB has no properties
Source File: http://shop.rsci.com/edit5.html
Line: 136

looks like the element passed into GetCheckedValue has no properties when
this line is executed:

if ( strRB.checked )



That function is called as: GetCheckedValue(document.forms[0].rdZS);
and without looking further I'll assume that rdZS is also in the
second form on the page.
 
D

David Rad

Thanks,

How do I distinquish between the two forms and their relative functions?
Or if you don't mind pointing me to a good search term/phrase to study
the proper syntax.

:)

David
 
L

Lee

David Rad said:
Thanks,

How do I distinquish between the two forms and their relative functions?
Or if you don't mind pointing me to a good search term/phrase to study
the proper syntax.

You could refer to them as forms[0] and forms[1], but that will
break if you add another form.

You may notice that most of the references to controls in the first
form look like, "document.frmItemInfo.Quantity.value", where the
second part of the reference is the form name.
If you rename your second form to remove the space, you could refer
to it in a similar way.

The FAQ for this newsgroup contains pointers to several good references:
http://www.jibbering.com/faq/
 
D

David Rad

Just to clarify:


<form method="post" action="javascript:DoNothing()"
name="Search_Results">"document.forms[0].func.value"),

and so on for each new form?

Thanks,

David

BTW, I changed the second to document.forms[1].* and it seems to work
http://shop.rsci.com/industrial_supplies_description.asp.
Though as you stated I'll have a problem when adding any additonal
form/s.
 
L

Lee

David Rad said:
Just to clarify:


<form method="post" action="javascript:DoNothing()"
name="Search_Results">"document.forms[0].func.value"),

and so on for each new form?

Yes.

Another point is that it's not a good idea to invoke a
javascript function as the action of a form. If you
don't have an URL that you want to submit the form data
to, then it would be cleaner to leave the action blank
and do your Javascript processing in the onSubmit event
handler. The handler should return false to prevent
the browser from trying to submit the form:

<form name="Search_Results" onsubmit="DoNothing();return false">
If, as the function name suggests, you're just trying to
disable submission (during development?), then just set
the onsubmit attribute to "return false".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top