Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have this form where if you enter the customer number the alternate ID is disabled and visa-versa when I submit a bad form via Ajax. When the response comes back both fields are able to be edited.

What I'm looking for is a better way to accomplish this. I realize that having a for loop within a for loop isn't most ideal.

success: function (data, textStatus, jqXHR) {
                        $("#content").replaceWith(data);
                        if (!$("#modalErrorDiv").is(':empty')) {
                            var customerNumber = "";
                            var alternateId = "";
                            var text = this.data.split('&');
                            for (var i = 0; i < text.length; i++) {
                                var key = text[i].split('=');
                                for (var k = 0; k < key.length; k++) {
                                    if (key[k] == 'customerNumber') {
                                        customerNumber = key[k + 1];
                                    }
                                    else if (key[k] == 'alternateId') {
                                        alternateId = key[k + 1];
                                    }
                                }
                            }
                            $("#customerNumber").val(customerNumber);
                            $("#alternateId").val(alternateId);
                            if (customerNumber != "") {
                                customerPoints.updateInputState($("#customerNumber"), $("#alternateId"));
                            }
                            if (alternateId != "") {
                                customerPoints.updateInputState($("#alternateId"), $("#customerNumber"));
                            }
                        }
                    }

this.updateInputState = function (input1, input2) {
            if (input1[0].value == undefined || input1[0].value == "") {
                input2.val("");
                input2.prop('disabled', false);
            }
            else {
                input2.val("");
                input2.prop('disabled', true);
            }
        };
share|improve this question
    
Please put only the code's purpose in the title. –  Jamal 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.