Link to home
Create AccountLog in
Avatar of JaCrews
JaCrews

asked on

Passing ClientID to Javascript from asp.net textbox

I have developed a site that uses both static ASP.net Textboxes and Dynamically created textboxes to hold dollar amounts.  I have also created a javascript that allows the user to type in " 1+2+3..." and onBlur will add the totals together.  Where i am running into an issue is I am not sure how to use the same function for all the textboxes.  I understand that the client ID will tell the javascript where to look, but how to I pass that client ID from the asp.net side in the onBlur? I know I will have to pass an argument un the javascript function, but have had trouble figuring this out. Any help is appreciated.

Javascript:
function solve() {
       
         with (Math) {
              answer = eval(document.getElementById("<%=txtCandy.ClientID%>").value);
              document.getElementById("<%=txtCandy.ClientID%>").value = answer;
         }
       
}

ASP textbox:
<td><asp:TextBox
          Width = "90px"
          ID="txtCandy"
          runat="server"
          ToolTip="Candy Total for the Day"
           />
       
    </td>

Attributes added in the Page_load section:
        txtCandy.Attributes.Add("onBlur", "solve(this);return false;")
ASKER CERTIFIED SOLUTION
Avatar of dakyd
dakyd

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of JaCrews
JaCrews

ASKER

I am so angry right now! thank you so much, it's always the little things that get me.
Heh, we've all done it.  At least you got it working now.  Cheers.