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!

On Change of Textbox calling Routine

Status
Not open for further replies.

nerdalert1

Programmer
Nov 4, 2004
92
US
Hello all. I have 12 textboxes on a form where currently I have a client control validator for each checking if the value is currency. How can I also call a sub routine either on the change or exit of the textbox to call a Total Sub Routine which adds up the textboxes and places it into a Total Textbox. I already have the routine to handle the total I just dont know how to kick off the routine on the exit of the box because I already have a validator doing a datatypecheck on each one. Thanks all.
 
you could add an onchange attribute to each of the text boxes...and include the client side validation in the routine

javascript function
function(txtboxID)
if txtboxID is not a number
alert('not a number');
return false;
} else {
add all the text boxes together

}
 
Can I call a VB Code Behind routine from within the javascript?
 
Only if you post back to the server.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
How would I do that? I have the textbox as Runat="server".
 
You would use a Server Control. e.g.
Code:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></form>
Set the SutoPostBack to True and use the TextChanged event. e.g.
Code:
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I needed the autopostback = true thats what I really needed. It seems to be working now. One last question I need to prompt the user if they want to roll the totals into the other textboxes. The routine is firing now correctly. How do I prompt the user with a Yes No dialog and then run my code? I know how to handle this within the code but this wont work on the client side correct? I have like:

Dim ianswer as integer

ianswer = MsgBox("Do you want to add all?", MsgBoxStyle.YesNo, "Add All")

If ianswer = vbYes Then
txtBox1.Text = txtBox2.Text
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top