1 (edited by dipan 2009-08-13 6:34:25 AM)

Topic: javascript array manipulation problem using xajax

Hi everyone

I am getting records from database and making javascript array using that.
I have created one page for this.
So when user click on link,ajax request goes and made javascript array like this
var DataArr = new Array();

DataArr[] = ["1","YUF","Mr. YUF","1","52495452",""];

DataArr[] = ["2","JGT","Mr. JGT","2","49545552",""];

DataArr[] = ["3","TAZ","Mr. TAZ","3","49564950",""];
.
.
.
. so on.
now i have one function in javascript e.g. setDataArr().
I want to manipulate this array in this function.
I am calling this function like $objResponse->script("setDataArr();");
But i am not able to manipulate.
Pls guide me on this.
Also guide me after creating this DataArr how could i send in page so javascript can handle.

Thanks in advance

Re: javascript array manipulation problem using xajax

You could send it as a parameret to setDataArr().

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: javascript array manipulation problem using xajax

I think you have to initialize DataArr before you fill it with xajax in your page, then xajax will fill this var and you can use it.

Re: javascript array manipulation problem using xajax

i have initialize DataArr as var DataArr = new Array();
so it is available in all scope of page.
But after assigning that values i am not able to access that DataArr in setDataArr().


I am giving you full description of my whole process
I have one page clients2.php

When this page load one xajax request goes to clientlist2.php and sets DataArr like this

DataArr[] = ["1","YUF","Mr. YUF","1","52495452",""];

DataArr[] = ["2","JGT","Mr. JGT","2","49545552",""];

DataArr[] = ["3","TAZ","Mr. TAZ","3","49564950",""];
.
.
.
. so on.

I have this function xajax_getMiddleContent2 for setting data.
in this function i am

$objResponse->script($data); // $data containse above javascript DataArr.
$objResponse->script("setDataArr();");

But it doesnt go in this function
function setDataArr()
{
    alert(DataArr)
}
setDataArr() function declared in clients.php page.
Pls guide me on this.
sorry for my bad english

Re: javascript array manipulation problem using xajax

Well now i see the problem, js does not support phpstyle to add new content to arrays like DataArr[] = 'new content';
you have to use DataArr.push('new content'); or DataArr[DataArr.length] = 'new content';