Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onChange work but give undefined or [object]

Status
Not open for further replies.

newtomysql

Technical User
Apr 11, 2001
96
MY
Dear All,
I have very simple javascript which I apply in my asp pages.

below is a snippet of my asp code first. here I am building dynamic name for each of record.
<input name="qty<%Response.Write Key%>" type="text" class="field-qty" onChange="orderTotal(this.form,'<%Response.Write Key%>')" value="<%=dictCart(Key)%>" size="5" maxlength="4" >

Here is my javascript code. I have purposely put alert(oform["qty1"]); which is suppose to take dynamic value. Even I have put a static value it give me undefined or sometimes it put [object]. I really cant see my problem here. Thanks.

function orderTotal(oform, prefix)
{

var qty = oform["qty1"];
alert(oform["qty1"]);
var price = oform["price"+prefix ];
var total = oform["total"+prefix ];
var subtotal = oform["subtotal"];
var temp = 0;
temp = subtotal.value - total.value;
temp2 = 0;

var hold;
// only bother if the field has contents
if (qty == "")return;

if(isNaN(qty.value) || (qty.value <= 0) || validate1(qty.value)==false)
{
qty.value = 1;
total.value = qty.value * price.value;
}
else
{
total.value = qty.value * price.value;

temp2 = Number(temp) + Number(total.value);

subtotal.value = temp2.toFixed(2);
document.forms.form1.submit();
}
}

 
I know this is going to sounds ridiculous, but did you actually confirm that you are creating a text field with the name "qty1"?

Can you post the generated HTML code from your ASP form in here? Please use the [ code ] tag as well to make it easier to read.

Thanks!
 
Dear Mikey,
Yes I have confirm it again. Below is my code I dont know how to use the
Code:
 tag. You can look in line no 364. Thanks.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>View Cart</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript" src="js/field-onfocus.js"></script>


<script type="text/javascript" language="javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>








<link href="front-css.css" rel="stylesheet" type="text/css">
<link type="text/css"  href="file_search.css" rel="stylesheet">
<script language="javascript" src="js/filesearchhover.js" type="text/javascript"></script>

<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<SCRIPT language=javascript>
function orderTotal(oform, prefix)
{

var qty = oform["qty1"];
alert(oform["qty1"]);
var price = oform["price"+prefix ];
var total = oform["total"+prefix ];
var subtotal = oform["subtotal"];
var temp = 0;
temp = subtotal.value - total.value;
temp2 = 0;

var hold;
// only bother if the field has contents
if (qty == "")return;

if(isNaN(qty.value) || (qty.value <= 0) || validate1(qty.value)==false)
   {
    qty.value = 1;
   total.value = qty.value * price.value;
   }
else
   {
    total.value = qty.value * price.value;
    
    temp2 = Number(temp) + Number(total.value);
   
    subtotal.value = temp2.toFixed(2);
    document.forms.form1.submit();
   }
}
</script>


</head>

<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
        
    <td width="998" height="100%" valign="top"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="998" height="94"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="94" style="font-family:Verdana, Geneva, sans-serif; font-size:24px; font-weight:bold">&nbsp;ABC.COM</td>
            <td align="right" valign="top"><table width="100%" border="0" height="94" cellspacing="0" cellpadding="0">
              <tr>
                <td height="11"></td>
              </tr>
              <tr>
                <td width="20%" align="right" valign="top"></td>
                </tr>
              
              
              
					
					
              <tr>
                <td align="right" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td><a href="front-view-cart.asp" >View Shopping Bag</a></td>
                        <td width="12"></td>
                      </tr>
                    </table></td>
                  </tr>
                  
                  <tr>
                    <td align="right"><table border="1" cellspacing="0" cellpadding="0">
                      <tr>
                        <td >Quantity</td>
                        <td ></td>
                        <td >Item Name</td>
                        <td ></td>
                        <td >Color</td>
                        <td ></td>
                        <td >Size</td>
                        <td ></td>
                        <td >Total Price</td>
                        <td ></td>
                      </tr>
                    </table></td>
                  </tr>
                   
                  <tr>
                    <td align="right"><table border="1" cellspacing="0" cellpadding="0">
                      <tr>
                        <td >1</td>
                        <td ></td>
                        <td >Bow Corset Top</td>
                        <td ></td>
                        <td >-</td>
                        <td ></td>
                        <td >-</td>
                        <td ></td>
                        <td >&nbsp;150.99</td>
                        <td ></td>
                      </tr>
                    </table></td>
                  </tr>
                  
                  
                  <tr>
                    <td height="11" align="right"></td>
                  </tr>
                </table></td>
                </tr>               
            </table></td>
            </tr>
        </table></td>
      </tr>
	  
      <tr>
        <td width="998"><table width="998" height="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="202" height="100%" align="center" valign="top" class="leftmenu-bg1"><script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<table width="170" height="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#66FFFF">
  <tr>
    <td height="15"></td>
  </tr>
  <tr>
    <td height="15"><a href="index.asp">Home</a></td>
  </tr>
  <tr>
    <td height="15"></td>
  </tr>	


  <tr>
    <td height="8"></td>
  </tr>
  <tr>
    <td valign="top"><table width="170" border="0" cellspacing="0" cellpadding="0">
         	
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
     
          <tr>
            <td width="1"></td>
            <td><a href="front-category.asp?Id=1&subsub=0&subsub2=&sorting=M.pitemrank&cend=asc, M.Itemname" >Top Dresss</a></td>
          </tr>
         
        </table></td>
      </tr>

      <tr>
        <td height="5"></td>
      </tr>
      	
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
     
          <tr>
            <td width="1"></td>
            <td><a href="front-category.asp?Id=2&subsub=0&subsub2=&sorting=M.pitemrank&cend=asc, M.Itemname" >Full Dresses</a></td>
          </tr>
         
        </table></td>
      </tr>

      <tr>
        <td height="5"></td>
      </tr>
      	
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
     
          <tr>
            <td width="1"></td>
            <td><a href="front-category.asp?Id=3&subsub=0&subsub2=&sorting=M.pitemrank&cend=asc, M.Itemname" >Long Pant</a></td>
          </tr>
         
        </table></td>
      </tr>

      <tr>
        <td height="5"></td>
      </tr>
      	
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
     
          <tr>
            <td width="1"></td>
            <td><a href="front-category.asp?Id=4&subsub=0&subsub2=&sorting=M.pitemrank&cend=asc, M.Itemname" >In Skirts</a></td>
          </tr>
         
        </table></td>
      </tr>

      <tr>
        <td height="5"></td>
      </tr>
      	
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
     
          <tr>
            <td width="1"></td>
            <td><a href="front-category.asp?Id=5&subsub=0&subsub2=&sorting=M.pitemrank&cend=asc, M.Itemname" >Fashion Bags</a></td>
          </tr>
         
        </table></td>
      </tr>

      <tr>
        <td height="5"></td>
      </tr>
      	
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
     
          <tr>
            <td width="1"></td>
            <td><a href="front-category.asp?Id=6&subsub=0&subsub2=&sorting=M.pitemrank&cend=asc, M.Itemname" >Others</a></td>
          </tr>
         
        </table></td>
      </tr>

      <tr>
        <td height="5"></td>
      </tr>
      	
    </table></td>
  </tr>
  <tr>
    <td height="16"></td>
  </tr>

  
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</td>
            <!-- start content -->
            <td width="796" height="100%" valign="top"><table width="796" border="0" cellspacing="0" cellpadding="0">

              <tr>
                <td height="15"></td>
              </tr>
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="20">&nbsp;</td>
                    <td><span class="font-title-18nopadleft">Shopping Bag</span></td>
                    <td width="20">&nbsp;</td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="5"></td>
              </tr>
              <tr>
                <td height="1" bgcolor="#CCCCCC"></td>
              </tr>

              <tr>
                <td>&nbsp;</td>
              </tr>

              
              <tr>
                <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="20">&nbsp;</td>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    	<form name="formcart" action="front-view-cart.asp" method=post ID="formcart">
			

                <tr>
                  <td height="20"></td>
                </tr>
                
                <tr>
                  <td width="100%" class="td-asline"><table width="100%" border="0" cellpadding="2" cellspacing="1">
                      <tr>
                        <td width="20" class="td-astitlebg"><span >No.</span></td>
                        <td class="td-astitlebg"><span >Item Name</span></td>
                        <td width="60" align="center" class="td-astitlebg"></td>
                        <td width="90" align="center" class="td-astitlebg"><span >U.Price</span></td>
                        <td width="60" align="center" class="td-astitlebg"><span >Qty</span></td>
                        <td width="120" class="td-astitlebg"><span >Total</span></td>
                        <td width="20" align="center" class="td-astitlebg"><span >Del.</span></td>
                      </tr>
                      
                      
                      
                      <tr>
                        <td height="60" valign="top" class="td-aswhite"><span >1</span></td>
                        <td class="td-aswhite" valign="top"><p>Bow Corset Top
                        </p>
                          <p>20 g</p></td>
                        <td height="60" align="center" class="td-aswhite"><img src='upload-images/Bow-Corset-Top-160.jpg' height="50" ></td>
                        <td align="center" class="td-aswhite"><span >150.99</span></td>
                        <td align="center">
                        <input name="qty1" type="text" class="field-qty" onChange="orderTotal(this.form,'1')"  value="1" size="5" maxlength="4"  >
                        </td>
                        <td class="td-aswhite"><input name="total" type="text" class="field-total" value="150.99" readonly style="width: 110px;"></td>
                        <td align="center" class="td-aswhite"><a href="front-view-cart.asp?Del=22#-#-"><img src="images/skin-1-trashbin.gif" border="0"></a></td>
                      </tr>
                     
                     
                     
			
                    </table></td>
                </tr>
                <tr>
                  <td height="5"></td>
                </tr>
                <tr>
                  <td class="td-asline"><table width="100%" border="0" cellpadding="2" cellspacing="1">
                      <tr>
                        <td align="right" class="td-astitlebg"><span >Subtotal&nbsp;&nbsp;</span></td>
                        <td width="149" align="right" class="td-aswhite"><input name="subtotal" type="text" class="field-subtotal" value="150.99" style="width: 149px;" readonly></td>
                      </tr>
                  </table></td>
                </tr>
 
                
                <tr>
                  <td height="5"></td>
                </tr>                
                <tr>
                  <td class="td-asline"><table width="100%" border="0" cellpadding="2" cellspacing="1">
                      <tr>
                        <td align="right" class="td-astitlebg"><span >Sum Weight&nbsp;&nbsp;</span></td>
                        <td width="149" align="right" class="td-aswhite"><span class="totalweight">95g</span></td>
                      </tr>
                  </table></td>
                </tr>
                   
             
                <tr>
                  <td height="30">&nbsp;</td>
                </tr>
			  </form>
          </table></td>
                    <td width="20">&nbsp;</td>
                  </tr>
                </table></td>
              </tr>
              	
              <tr>
                <td class="font12astitle" style="padding-left: 20px;"><span class="style1"></span></td>
              </tr>
              <tr>
                <td style="padding-left: 20px;">&nbsp;</td>
              </tr>
              
              <tr>
                <td style="padding-left: 20px;"><table border="0" cellpadding="2" cellspacing="0">
    <form name="vcheck" action="front-checkout.asp" method="post">

                      <tr>
                        <td height="10"> </td>
                        <td> </td>
                      </tr>

                      <tr>
                        <td height="20"><a href="front-checkout.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('butcheckout','','images/skin-1-but-checkout-2.jpg',0)"><img src="images/skin-1-but-checkout-1.jpg" name="but-checkout" border="0" id="butcheckout"></a></td>
                        <td class="alert"></td>
                      </tr>
     </form>                 
    </table></td>
              </tr>
              

              <tr>
                <td height="30">&nbsp;</td>
              </tr>
            </table></td>
            <!-- end content -->
          </tr>
        </table></td>
      </tr>
            <tr>
        <td width="998" height="40" align="center" bgcolor="#000066" class="copy">&copy; 2009 ABC.com</td>
      </tr> 
    </table></td>
	  
  </tr>
</table>
</body>
</html>
 
Hi

I find only other kind of errors :
[ul]
[li]there is no total1 [tt]input[/tt], only total[/li]
[li]there is no price1 [tt]input[/tt][/li]
[li]there is no form1 [tt]form[/tt][/li]
[/ul]

Feherke.
 
Dear Feherke,
Yes I know I have those fields to be added. The problem I cant even get the first value of qty1. So how must I solve this ? Thanks.
 
Dear Feherke,
I am using explorer version 6.0.2900. Is it due to my browser is it ?
 
I see the issue now... you aren't using qty properly. You are using "qty" as an object AND as a variable that holds the value. Changes are below in red...

Code:
<SCRIPT language=javascript>
function orderTotal(oform, prefix)
{

var qty = oform["qty1"];
alert(oform["qty1"][COLOR=red].value[/color]);
var price = oform["price"+prefix ];
var total = oform["total"+prefix ];
var subtotal = oform["subtotal"];
var temp = 0;
temp = subtotal.value - total.value;
temp2 = 0;

var hold;
// only bother if the field has contents
if (qty[COLOR=red].value[/color] == "")return;

if(isNaN(qty.value) || (qty.value <= 0) || validate1(qty.value)==false)
   {
    qty.value = 1;
   total.value = qty.value * price.value;
   }
else
   {
    total.value = qty.value * price.value;
    
    temp2 = Number(temp) + Number(total.value);
   
    subtotal.value = temp2.toFixed(2);
    document.forms.form1.submit();
   }
}
</script>

Using the above AND what Feherke mentioned, you should be able to fix this.

FYI... under the text area where you enter your reply, there is a link called Process TGML. Click that and it will show you how to use [ code ] and other spiffy tags.
 
Dear Friends,
Thank you very much for your kind solution it solve my problem many thanks.
 
I dont know how to use the [ignore]
Code:
[/ignore] tag[/quote]

Let me show you, because you don't use it any of your posts that I can see.

When posting code, right before the code starts, you type:

[ignore][code][/ignore]

And right after the end of the ode, you type:

[ignore]
[/ignore]

So, your code block will look like this:

[ignore]
Code:
... Some code here ...
... Possibly on multiple lines...
[/ignore]

So instead of looking like this (to use part of your example above):

if(isNaN(qty.value) || (qty.value <= 0) || validate1(qty.value)==false)
{
qty.value = 1;
total.value = qty.value * price.value;
}

It would look a lot nicer:

Code:
if(isNaN(qty.value) || (qty.value <= 0) || validate1(qty.value)==false)
{
   qty.value = 1;
   total.value = qty.value * price.value;
}

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Dear Billy,
Thank you for your info next time i will follow ok.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top