0

I am calling two separate functions to generate dynamic textboxes one of the function works fine whereas other doesn't work though the code for generating textboxes is same except the variables names and label names. Could anyone please let me know what I am doing wrong and how can i figure out this ?

this is the function which is not working.

           var C = 3;
       var matrixArray = ["question", "mrank"];

       $("#addMatrix").click(function () {
         for(var j = 0; j < matrixArray.length; j++){
            createMatrixInput(MatrixArray[j]);
         }
         C++;
       });
function createMatrixInput(l){
            var tb_Div = $('#TextBoxes');
            var mstr = '<div class="control-group">';
            mstr += '<label class="control-label">' + l + " " + C + '</label>';
            mstr += '<div class="controls">';
            mstr += '<input type="text" id="' + l + '_' + C + '" name="'+ l +'_' + C + '" />';
            mstr += '</div>';
            mstr += '</div>';
            tb_Div.append(mstr);
        };

this is my jsfiddle with complete code.

http://jsfiddle.net/qqqyC/2/

1
  • 1
    jsbeautifier.org Commented Nov 18, 2013 at 15:31

2 Answers 2

1

There are 2 problems. The button id is addmatrix and the array is matrixArray, not MatrixArray. The method should look like:

$("#addmatrix").click(function () {
    for(var j = 0; j < matrixArray.length; j++){
        createMatrixInput(matrixArray[j]);
        C++;
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Oh that's the good catch man. Case sensitivity is crazy. So now its clear we can call as many as functions on same page without any issues, its great.
nice, two case sensitive mistakes =p i've spotted only one haha :p
1

I've spotted a error in your JSFiddle see the id of your button "matrix button" it is addmatrix and you are binding the onClick event to addMatrix and javascript event binding via ID is case sensitive, so the event will not be bind.

Maybe this will solve your whole problem, because it was preventing to execute the click event.

2 Comments

Once the event click it will generate two textboxes as I am passing l as a parameter in CreateMatrixInput function. Though same function I am using and its works fine if you have a look on jsfiddle.net/qqqyC/1
Still same no success.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.