Path

ez projects / ezxajax / forum / general / how to pass variable from ....


how to pass variable from .js to .php ?

You need to be logged in to post messages in the forums. New users may register here.

Mickael Robin

Member since:
29 January 2008

Posts: 17

Wednesday 26 November 2008 3:51:31 pm

Hi all,

I'm trying to set up an ajax "in-line" edit mechanism.

Basically, I want to replace the attribute content with an input html tag, and then have the value of this input element sent as a parameter from a function in my js file to the php one.

It seems that variable content is not naturally passed => shall I pass variables with url+GET method or with form+POST method???

Thanks in advance for your help.

You cand find my "as is" code below
##############################
- in the .tpl



<h1 ondblclick="inlineMod(this)">{attribute_view_gui attribute=$node.data_map.name}</h1>




- in the .js



function inlineMod(obj)


{


        //Objet servant à l'édition de la valeur dans la page


        var input = null;


 

        input = document.createElement("input");


        


        //Assignation de la valeur


        if (obj.innerText)


                input.value = obj.innerText;


        else


                input.value = obj.textContent;


                


        //Recuperation du texte a remplacer     


        old = obj.childNodes[2];


                


        //Remplacement du texte par notre objet input


        obj.replaceChild(input, old);


 

        //On donne le focus à l'input et on sélectionne le texte qu'il contient


        input.focus();


        input.select();


                


        //Sortie de l'input


        input.onblur = "xajax_editattribute(input.value)";


}




- and in the .php



function editattribute($variable)


{


        $objResponse = new xajaxResponse();


        $objectID           = '1';


        $attributeIdentifier = 'name';


        $attributeValue     = $variable;


        $contentObject      = eZContentObject::fetch( $objectID );


       $curVersionObject = $contentObject->attribute( 'current' );


       $objectDataMap   = $curVersionObject->attribute('data_map');


        $objectDataMap[$attributeIdentifier]->setAttribute("data_text", $attributeValue );


        $objectDataMap[$attributeIdentifier]->store();


       return $objResponse;


}




=> how can I have the php file retrieve the value of "$variable" so I can change the value of the attribute?
Up

You need to be logged in to post messages in the forums. New users may register here.