0

From the start I'd like to say I know very little jQuery - I've been using small scripts now for around a week now. It is a useful tool, but I am unsure if what I am looking to achieve is even possible.

I have a table layout as shown in this JS Fiddle, an 8 column layout. What I am looking to achieve is if the text is MATCH TEXT in column 2, row 2 and the textbox has the number 3 in it that this will then update the other two textboxes with a zero.

I have found this slightly similar code from another StackOverflow post:

$('#txtAmt').change(function() {
    var txtAmtval = $('#txtAmt').val();
    $('#txtInterest%').val(txtAmtval);
});

The thing is that while these sets of values appear in my table in groups of three, I might want to autoupdate the the 2nd and 3rd rows, or 1st and 3rd, or 1st and 2nd - so I don't think I can reference the name tag of the textboxes.

I have searched the internet but I cannot find out if this is possilble or how to implement it?

1 Answer 1

1

Just give all your textboxes the same class name. In your fiddle, I saw that you use the class errorMessage. So just do it as simple as

$(".errorMessage").change(function(){
//Maybe you have more logic
     if ($(this).val() == 3){
         $(".errorMessage").not(this).val(0);
     }
});

Fiddle

3
  • This is good, I've modified it slightly to change based on the classes - but can it be expanded to only change if the value entered is 3? jsfiddle.net/hkhUQ/3 Jun 5, 2013 at 10:52
  • 1
    @Dustin Cook: well, just add one more check if ($(this).val() == 3). Check out my updated answer
    – Khanh TO
    Jun 5, 2013 at 10:54
  • Magic - that got it working - I think I see were I went wrong now. Jun 5, 2013 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.