Link to home
Start Free TrialLog in
Avatar of WEhalt
WEhaltFlag for United States of America

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.
Avatar of jello024
jello024

<input type="text" onchange="javascritpFunction();" />
Avatar of WEhalt

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.toString(), 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('Rev', 'Ton');
                    var ThisObjectTon = document.getElementById(ThisStringTon);
                    if (Number(ThisObjectTon.value) <= 0) {
                        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.
Avatar of WEhalt

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("OriginalValue", 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
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial