0

I need to combine 2 variable names, but it must be in a for loop. Also I need to get the variable from a php file to know how long the loop must be.

I have while loop in php file which count how many objects I have and make "$k++" for every object. After while loop I have variable what store count of objects $galak=$k-1 ... I need to make javascript something like:

document.getElementById("galak");
var i;
for (i = 1; i < galak; i++) {
    var decimalMask.i = new InputMask(JST_MASK_DECIMAL, "rdcena".i);
}

After loop "for" there must be decimalMask1,decimalMask2,decimalMask3 etc. and rdcena1,rdcena2,rdcena3 etc.

So question is how to add variable "i" value to other variables decimalMask and rdcena?!

1 Answer 1

1

Try to concatenate them. Replace . with +. + is the concatenation operator in javascript. And make decimalMask an array.

decimalMask[i] = new InputMask(JST_MASK_DECIMAL, "rdcena" + i);

Then it can be accessed as decimalMask[1] or decimalMask[2]...

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm.. it would be good to make array and store 'new InputMask(JST_MASK_DECIMAL, "rdcena" + i)' there. Can you show how to make string array decimalMask and then use 'var decimalMask[i] =' ?
Just define it - var decimalMask = []
Now all work fine except "document.getElementById("galak");".. seems like it don't read value stored in it.. mby you could make solution? because loop "for (i = 1; i < 13; i++) " works good, but for (i = 1; i < galak; i++) don't work at all..

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.