Dear members of MPGH

I have a small problem. I need to make a latin square. The latin square looks like a sudoku. But only the rows and colums need to be checked for the right answer.
An example of a 4x4 latin square:
1234
2341
3412
4123

or 3x3
123
231
312

Anyway, I have a script, with imput an array. 0 marks the empty spots, that needs to be replaced with the right number.

This is what I have now:
Code:
var square = [[1,0,3],[2,0,1],[0,1,0]];

for(var a = 0; a<square.length; a++){
for(var b = 0; b<square.length; b++){
if(square[a][b] === 0) {
enter function here

}

}
}

At enter function here I need to implement a backtracking algorithm, but I have no clue how to.

I hope someone could give me a kick in the right direction. You can answer me here or add me on skype: thechib12

Thanks in advance,

ChiB