0

I have a separate array like

1 1 1
2 2 2
3 3 3

I need to pass this array to JavaScript function as a parameter while onChange action is called.

can anyone give me a suggestion for that?

Thanks.

5
  • 1
    What have you tried? Commented Jan 6, 2012 at 9:31
  • I have assigned that array into one variable and passed it like onchange('arrayname'). But it was not passed Commented Jan 6, 2012 at 9:39
  • What's onchange in this case? Could you please provide a complete example, preferably with jsfiddle.net demo? Commented Jan 6, 2012 at 9:41
  • Can you show some of your code??? Commented Jan 6, 2012 at 10:49
  • Please show your code. Is that supposed to be a two-dimensional array, or...? Commented Jan 6, 2012 at 10:50

3 Answers 3

0

Try something like below

var x1=[1,11,11];
var x2=[2,21,22];
var x3=[3,31,32];
var y=[x1,x2,x3];
onChange(y);
Sign up to request clarification or add additional context in comments.

Comments

0

Don't know if that's an option, but this is how it may work in jQuery:

HTML:

<textarea id="target" />

jQuery:

$(document).ready(function(){
    $('#target').change(function() {
      var arr1 = [1,2,3];
      var arr2 = [1,2,3];
      var arr3 = [1,2,3];
      var arr = [arr1, arr2, arr3];
      //do whatever you want with it
      alert(arr);
});
});

I guess you could assign it to some hidden element (like input hidden) and then write some code that would read the arr value from it.

At least that's one of options - I'm not sure what you're trying to achieve.

Hope this helps

Comments

0

You need to wrap the function call in another anonymous function.

element.addEventListener('change', function(e){
    yourFunction(yourArray);
});

Comments

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.