Javascript Error - Please Help

Last post 07-06-2008 11:11 PM by BlueTSX. 2 replies.

Sort Posts:

  • Javascript Error - Please Help

    07-06-2008, 10:39 PM
    • Member
      127 point Member
    • BlueTSX
    • Member since 05-21-2004, 4:01 PM
    • Posts 74
    ClientScript.RegisterClientScriptBlock(Me.GetType(), "ShowTotal", "function ShowAge() " & vbCrLf & _

    "{" & vbCrLf & _

    " var Price, Qty, Total;" & vbCrLf & _

    " var Price = document.getElementById('" & txtUnitPrice.ClientID & "');" & vbCrLf & _

    " if (Price != null)" & vbCrLf & _

    " Qty = document.getElementById('" & txtQty.ClientID & "');" & vbCrLf & _

    " Total = Qty.value * Price.value;" & vbCrLf & _

    " document.getElementById('" & txtTotal.ClientID & "').value = Total.value;" & vbCrLf & _

    " alert('Price= ' + Price.value + ' Qty= ' + Qty.value + ' Total= ' + Total.value);" & vbCrLf & _

    "}", True)

     

    All I am adding the above JS script onto my content page in ASP.Net. The content page is using a Master Page. Everything in the above script works just fine, but I keep getting an error "UNDEFINED" on Total? Why oh why am I getting this error, please help me! This is driving me nuts! The alert is there just for testing/debugging purposes. The other two fields Price and Qty display just fine without any errors. All three of these items are textboxes on my web form.

    Thanks!

  • Re: Javascript Error - Please Help

    07-06-2008, 10:53 PM
    Answer
    • All-Star
      30,502 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 5:53 PM
    • Dhaka, Bangladesh
    • Posts 3,292
    • Moderator
      TrustedFriends-MVPs

    Total is a variable. It holds the result of a multiplicattion. Hence you can't have Total.value. So, it should be like:

    Total = Qty.value * Price.value;

    document.getElementById('" & txtTotal.ClientID & "').value = Total;

    And replace Total.value with Total inside the alert too.

    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: Javascript Error - Please Help

    07-06-2008, 11:11 PM
    • Member
      127 point Member
    • BlueTSX
    • Member since 05-21-2004, 4:01 PM
    • Posts 74

    Thanks so much! That worked like a charm!

Page 1 of 1 (3 items)