We help IT Professionals succeed at work.

Passing ClientID to Javascript from asp.net textbox

JaCrews
JaCrews asked
on
21,669 Views
Last Modified: 2013-11-07
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;")
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I am so angry right now! thank you so much, it's always the little things that get me.

Commented:
Heh, we've all done it.  At least you got it working now.  Cheers.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.