WEhalt
asked on
Javascript - Form Changes
Is there a way to tell if a textBox value has been changed since it was loaded?
I would like to run a function to validate a value, but only if another field has changed.
I do not want to bother the user with a potential error message if they have not had a chance to enter all of their changes yet.
I would like to run a function to validate a value, but only if another field has changed.
I do not want to bother the user with a potential error message if they have not had a chance to enter all of their changes yet.
<input type="text" onchange="javascritpFuncti on();" />
ASKER
Obviously I need to increase the point value, because I have no idea what to do with what I was just given above.
Here is what I am trying to create
function CkBusRules(ThisTextBox ) {
//Check the suffix of the object, if it is Rev, test it If Rev > 0, Ton must be > 0
var ThisEndString = Right(ThisTextBox.id.toStr ing(), 3);
if (ThisEndString == 'Rev' && Number(ThisTextBox.value) > 0) {
--> here I need to also check to see if the user has changed ton. If they have not I want to abort the test.
The names of the objects are carefully planned so they correspond and this fx can be used with all 50 fields.
txtGroupNameRev has a corresponding txtGroupNameTon
var ThisStringTon = ThisTextBox.id.toString(). replace('R ev', 'Ton');
var ThisObjectTon = document.getElementById(Th isStringTo n);
if (Number(ThisObjectTon.valu e) <= 0) {
alert('An entry in revenue requires an entry in tons');
return false;
}
else {
return true;
}
}
Here is what I am trying to create
function CkBusRules(ThisTextBox ) {
//Check the suffix of the object, if it is Rev, test it If Rev > 0, Ton must be > 0
var ThisEndString = Right(ThisTextBox.id.toStr
if (ThisEndString == 'Rev' && Number(ThisTextBox.value) > 0) {
--> here I need to also check to see if the user has changed ton. If they have not I want to abort the test.
The names of the objects are carefully planned so they correspond and this fx can be used with all 50 fields.
txtGroupNameRev has a corresponding txtGroupNameTon
var ThisStringTon = ThisTextBox.id.toString().
var ThisObjectTon = document.getElementById(Th
if (Number(ThisObjectTon.valu
alert('An entry in revenue requires an entry in tons');
return false;
}
else {
return true;
}
}
The approach that I have suggested in that thread is that when populating each textbox, you can also add an additional attribute into it which has the same value as the text. Then you can compare that attribute with the text to see if the original value has been changed.
ASKER
OK - now I see it. There was just too much there and I didn't know what I was supposed to glean from it. I figured I could add custom attributes but had no clue how.
So, is this the correct syntax to add an attribute?...
<asp:TextBox ID="txtGate3rdPartyTon" runat="server" Width="63px" originaltext="value"></asp :TextBox>
or do I have to use
mytextbox.Attributes.Add(" OriginalVa lue", value)
Another question, will reloading the form reset originaltext to the new value?
With that, I should be able to design the rest of it.
Thanks for your patience.
W
So, is this the correct syntax to add an attribute?...
<asp:TextBox ID="txtGate3rdPartyTon" runat="server" Width="63px" originaltext="value"></asp
or do I have to use
mytextbox.Attributes.Add("
Another question, will reloading the form reset originaltext to the new value?
With that, I should be able to design the rest of it.
Thanks for your patience.
W
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.