Topic: Calling a xajax function with a submit causes error

Hi,
I'm trying to do a script with php and xajax but I can't find a solution to make it works :

HTML CODE

Code: PHP

<div id="table1" style="overflow:auto;height:150 px;">

<form action="" method="post" name="theform">

        <input type="hidden" name="called" value="editliens">

        <input type="hidden" name="offset" id="offset" value="">

        <input type="text" name="year">

        <input type="text" name="month">

        <input type="text" name="day">

        <input type="Button" value="Afficher" onClick="jerempli();xajax_tab_rempli(offset);return false;">

</form>

JS CODE

Code: PHP

function jerempli()

{

       var ye=document.getElementById('year');

       var mo=document.getElementById('month');

       var da=document.getElementById('day');

       var de=ye.value+"-"+mo.value+"-"+da.value;

      offset.value=de;

}

PHP CODE

Code: PHP

function tab_rempli($date)

{    global $variable;

    dbconnect();   # CONNECT TO THE DATABASE

    $query='SELECT `newsid`, `newsheadline`,`surtitle` FROM `news` WHERE newsdate=\''.$date.'\'';

    $result=mysql($variable[dbname], $query);

    $newsdetails = mysql_fetch_array($result);

    while(list($newsid,$newsheadline,$surtitle)=mysql_fetch_row($result)):

        $query2="INSERT INTO `gauche` VALUES('$newsid', '$newsheadline', '$surtitle')";

        $result2=mysql($variable[dbname], $query2);

    endwhile;

       # NEED THEN TO CALL fen_rempli function after this to display the results. I have do to this cause

       # fen_rempli is also called in another place of the script.

}



function fen_rempli()

{    global $variable;

    dbconnect();

    $objResponse = new xajaxResponse();

    $la_table='<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center" id="tablo">';

    $query="SELECT * FROM `gauche` WHERE 1";

    $result=mysql($variable[dbname], $query);

    while(list($newsid,$newsheadline,$surtitle)=mysql_fetch_row($result)):

        $la_table.="<tr>\n".'<td>'."\n";

        $la_table.=$surtitle.'<br>'.$newsheadline."</td>\n</tr>\n";

    endwhile;

    $la_table.="</table>\n";

    $objResponse->addAssign("table1","innerHTML",$la_table);

    return $objResponse;

}



$xajax->processRequests();

My problem is, if I let this script as is I got a "too much recursion" error on xajax.js and my script doesn't work.
I tried to change the operation of the submit by just calling jerempli function and then in it called tab_rempli then fen_rempli. But the script doesn't works well by finishing too fast and don't display every time the results.

As you see I have to sort some record fields from a big table and put them in another little one then display them.

Can any one help me. Thanks

Re: Calling a xajax function with a submit causes error

What is "offset"? A global var? an object? You passed a var called "offset" (xajax_tab_rempli(offset);) but I can't see where you define it.

If you want to pass the value of the input field "offset" you have to use: xajax_tab_rempli(xajax.$('offset').value);

Re: Calling a xajax function with a submit causes error

In html code it's a hidden field. The second one.
The value is well recognized by the script.

I forget to say : xajax version 0.2.5


----------------------
The truth is somewhere else

Re: Calling a xajax function with a submit causes error

I found my error by searching (a lot) in the other posts.
I changed this line in the html code.

Code: PHP

<input type="Button" value="Afficher" onClick="xajax_tab_rempli(xajax.getFormValues('theform'));return false;">

Then catched the date there in php code:

Code: PHP

function tab_rempli($theform)

{    global $variable;

$objResponse = new xajaxResponse();

$date=$theform['year'].'-'.$theform['month'].'-'.$theform['day'];

    dbconnect();

    $query="TRUNCATE TABLE `gauche`";

    $result=mysql($variable[dbname], $query);

    $query="TRUNCATE TABLE `droite`";

    $result=mysql($variable[dbname], $query);

    $query='SELECT `newsid`, `newsheadline`,`surtitle` FROM '.$variable[newstable].' WHERE newsdate=\''.$date.'\'';

    $result=mysql($variable[dbname], $query);

    $newsdetails = mysql_fetch_array($result);

    while(list($newsid,$newsheadline,$surtitle)=mysql_fetch_row($result)):

        $query2="INSERT INTO `gauche` VALUES('$newsid', '$newsheadline', '$surtitle')";

        $result2=mysql($variable[dbname], $query2);

    endwhile;

    $objResponse->addScriptCall("xajax_fen_rempli");

    return $objResponse;

}

#the other lines are the same

Last edited by kabkab (2008-01-08 12:53:16 PM)