Validate the textbox

GirishSharma

Member
Joined
Feb 2, 2009
Messages
5
Programming Experience
Beginner
Hello,

I have placed 5 textboxes on a web page (ASP.NET using VB) and one for input of sum above 5 textboxes. I want to validate the 6th textbox as a sum of above 5 values; something like it.. suppose sum of 5 textboxes is 1032 and now focus is in 6th (i.e. total) textbox; so here only "1032" characters should be allowed no other; and they should be in this order only; not like 1302 or something like (after pressing 1 it will accept only 0 no other key). How to get this feature please tell me. I have searched and got javascript examples but none is having the solution of my query.

User has to feed the sum of above 5 values in the 6th textbox; so that if there is any error in source (a pri-printed data sheet which comes from other department); may be returned back to avoid wrong data input in database.

Thanks & Regards
Girish Sharma
 
To get that kind of refinement you'll have to do a bunch of post backs for each key pressed, not good.

What you could do is use a javascript to prevent post back if the 6th textbox doesn't have the correct number in it and of course display a message to the user if it's incorrect.
 
Thanks JuggaloBrotha. I was aware that in my case only Javascript is the best bet to get the solution; but i am not having any much exposure in JS; so i request you to please give me javascript or any link where similar functionality is in action.

Thanks & Regards
Girish Sharma
 
I'm no expert with javascript, but I'll see what I can do when I have some free time the next couple of days.

In the mean time, this would be a great time for you to read up on javascript and possibly make a script that works the way you want it to.
 
In mean time; i will:
1.More google to get the similar JS or;
2.Consult with my friends or;
2.Wait for your reply.

because reading the Javascript from scratch and touch the level of "workable knowledge" would require at least 6 months; just because tiny mind :)

Thanks & Regards
Girish Sharma
 
here's a start:
VB.NET:
    <script language="javascript" type="text/javascript">
        function CheckTBs() {
            alert(document.getElementById('Textbox4').value != document.getElementById('Textbox1').value + document.getElementById('Textbox2').value + document.getElementById('Textbox3').value);
        }
    </script>
 
First off, i wish to thanks for keeping my query in your "To Do List".

Though, i have'nt incorporated your code in my project; i am telling you what i have done so far:

1.I have set AutoPostBack=True of TextBox10 (i.e. Total Textbox).
2.Protected Sub TextBox10_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox10.TextChanged

If Val(TextBox10.Text) <> (Val(TextBox2.Text) + Val(TextBox3.Text) + Val(TextBox4.Text) + Val(TextBox5.Text) + Val(TextBox6.Text) + Val(TextBox7.Text) + Val(TextBox8.Text) + Val(TextBox9.Text)) Then
Label3.Visible = True
Label3.Text = "Total Mismatch...! Should be " & (Val(TextBox2.Text) + Val(TextBox3.Text) + Val(TextBox4.Text) + Val(TextBox5.Text) + Val(TextBox6.Text) + Val(TextBox7.Text) + Val(TextBox8.Text) + Val(TextBox9.Text))
TextBox10.Focus()
Else
Label3.Visible = False
Button1.Visible = True
Button1.Focus()
End If
End Sub

I think your code will return an alert message of difference; but i do'nt want this functionality. I want that user can only enter right digits of sum or on escape key it should lost focus/come of textbox like that.

Best Regards
Girish Sharma
 
Back
Top