Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hello people here is my code

function send(Eqt_Param,Eqt_Param_value)
{
    var Eqt_Paramv=Eqt_Param+'='+Eqt_Param_value;
    alert(Eqt_Paramv);
}

every time Eqt_Param and Eqt_Param_value will be different ...iam sending values onclick so run this script for 5 times well i get 5 different values overall.but now i need to save each value in an array so that i can use the array element in the script function again,

plzz help me to fix this

share|improve this question
    
In which function would you like to store the values? –  specialscope Nov 28 '12 at 5:30

3 Answers 3

var data = new Array();

function add(param, value){
    var temp = {'param' : param, 'value' : value};

    if (data.length >= 50)
        data.shift();

    data.push(temp);        
}

Call the function after the processing like

add(Eqt_Param,Eqt_Param_value);
share|improve this answer
    
i don't see message anywhere in the script... i think that should be temp.... :) –  bipen Nov 28 '12 at 5:37
    
You are right.. :) –  sheldonCooper Nov 28 '12 at 5:39

Create a global array variable, and simply assign the function to it.

 
  var array = [];
  function send(param, param_value) { 
    array[] = Eqt_Param + '=' + Eqt_Param_value;  
  }
 

or

 
  var array = [];
  array[] = send(param, param_value);
  function send(param, param_value) { 
    return Eqt_Param + '=' + Eqt_Param_value;  
  }
 

The array will contain all the results anytime the function is run.

Hope this helps.

share|improve this answer
    
to check the number of elements in the array, try alert(array.length); –  Kneel-Before-ZOD Nov 28 '12 at 6:00
    
What code did you use? –  Kneel-Before-ZOD Nov 28 '12 at 6:06
    
why would you want to pass a javascript code to another javascript file? Something's amiss there –  Kneel-Before-ZOD Nov 28 '12 at 6:18
    
to obtain the values in an array, use something like for (var i =0; i < array.length; i++){alert(array[i]);} ; something like that. –  Kneel-Before-ZOD Nov 28 '12 at 6:22
    
no no iam not passing it to another javascript file,i want to passit to another php file,no issues with that i have tried that method earlier,,, but right now i need to check and make sure javascript array has all the values that i wanna pass,i tried document.write but it is showing [object object] –  Friend Nov 28 '12 at 6:22

not sure if this is what u want... but u can try this out..

create a global array...

var globalArray=[];

use push() to push the values u want in the array

function send(Eqt_Param,Eqt_Param_value)
{
   var Eqt_Paramv=Eqt_Param+'='+Eqt_Param_value;
    alert(Eqt_Paramv);
   globalArray.push(Eqt_Paramv);   // i am pushing the result(Eqt_Paramv) here, 
}
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.