Welcome Guest, Not a member yet? Register   Sign In
using xajax in button and textfield
#1

[eluser]pandjie[/eluser]
Hi,
I have a problem in using xajax and CI. I have a button and a textfield input. I want a scenario like this : when the button pressed, some text displayed in text field input. I have code like this :

Code:
<?php
    class Formajax Extends Controller {
        function Formajax(){
            parent :: Controller();
            $this->load->library('xajax');
            $this->load->helper('url');
            $this->xajax->registerFunction(array ('process_form',& $this,'process_form'));
            $this->xajax->processRequest();
        }
        
        function process_form($form_data){
            $objResponse = new xajaxResponse();
            $result = "Your name is  panji";
            $name = $form_data['txt_value'];
            
            $objResponse->addAssign($name, "value", $result);
            return $objResponse;
        }
        
        function index(){
            $template['xajax_js'] = $this->xajax->getJavascript(base_url());
            $this->load->view('coba/form',$template);
        }
    }
?>


and HTML code like this :
Code:
<form name="ajaxform" id="ajaxform" onsubmit="return false;">
               <input type="submit" value="submit" onclick="xajax_process_form(xajax.getFormValues('ajaxform'));"/>
          <input type="text" name="txt_value" value="" size="20"/>

  </form>

but, when I pressed the button no text was displayed.
what's wrong ?
#2

[eluser]sansanwawa[/eluser]
[quote author="pandjie" date="1208158118"]Hi,
I have a problem in using xajax and CI. I have a button and a textfield input. I want a scenario like this : when the button pressed, some text displayed in text field input. I have code like this :

Code:
<?php
    class Formajax Extends Controller {
        function Formajax(){
            parent :: Controller();
            $this->load->library('xajax');
            $this->load->helper('url');
            $this->xajax->registerFunction(array ('process_form',& $this,'process_form'));
            $this->xajax->processRequest();
        }
        
        function process_form($form_data){
            $objResponse = new xajaxResponse();
            $result = "Your name is  panji";
            $name = $form_data['txt_value'];
            
            $objResponse->addAssign($name, "value", $result);
            return $objResponse;
        }
        
        function index(){
            $template['xajax_js'] = $this->xajax->getJavascript(base_url());
            $this->load->view('coba/form',$template);
        }
    }
?>


and HTML code like this :
Code:
<form name="ajaxform" id="ajaxform" onsubmit="return false;">
               <input type="submit" value="submit" onclick="xajax_process_form(xajax.getFormValues('ajaxform'));"/>
          <input type="text" name="txt_value" value="" size="20"/>

  </form>

but, when I pressed the button no text was displayed.
what's wrong ?[/quote]





Hi Panjie,

try add an id for the element of your html

Code:
<input type="text" name="txt_value" id="txt_value" value="" size="20"/>

just try in case of basic xajax function first

Code:
function process_form($form_data){
            $objResponse = new xajaxResponse();
            $result = "Your name is  panji";
             $name = $form_data['txt_value'];
           //$name =  'txt_value';
           //$name is param of an "id" of an element and its not a "name" of an element
            $objResponse->addAssign($name, "value", $result);
            return $objResponse;
        }


Warmest Regards
#3

[eluser]pandjie[/eluser]
I have added 'id' but it still can't work.
#4

[eluser]sansanwawa[/eluser]
[quote author="pandjie" date="1208170346"]I have added 'id' but it still can't work.[/quote]

Hi,Pandjie

have u tried

Code:
$name = 'txt_value'

as i said before

Code:
$objResponse->addAssign($an_Id_Of_YourElement_Not_a_value_Or_name_of_your_element,"value","test");
...Edit...

Here is from xajaxResponse.inc.php class,you can read for usage.

Code:
/**
     * Adds an assign command message to the XML response.
     *
     * <i>Usage:</i> <kbd>$objResponse->addAssign("contentDiv", "innerHTML", "Some Text");</kbd>
     *
     * @param string contains the id of an HTML element
     * @param string the part of the element you wish to modify ("innerHTML",
     *               "value", etc.)
     * @param string the data you want to set the attribute to
     */



Regards
#5

[eluser]pandjie[/eluser]
do you mean something like this ?

Code:
function process_form($form_data){
            $objResponse = new xajaxResponse();
            $name = 'txt_value';
            $objResponse->addAssign($name, "value", "test");
            return $objResponse;
        }

and

Code:
&lt;form name="ajaxform" id="ajaxform" onsubmit="return false;"&gt;
          This is your name :
          &lt;input type="text" id="txt_value" name="txt_value" size="20"/&gt;
          &lt;input type="submit" value="submit" onclick="xajax_process_form(xajax.getFormValues('ajaxform'));"/&gt;
  &lt;/form&gt;

It still doesn't work. I'm confusing. Is that about xajax version ?
I use xajax0.5 beta 4b.
#6

[eluser]sansanwawa[/eluser]
Hi,pandjie

are u using your php with "display_error" = "off"?
Try for my complete code..

controller :
Code:
class Welcome extends Controller {

    var $objRes;

    function Welcome()
    {
         parent::Controller();
         $this->objRes = new xajaxResponse();
         $this->xajax->registerFunction(array ('process_form',& $this,'process_form'));
         $this->xajax->processRequests();
    }
    
    function index()
    {
        $data['Printjavascript'] = $this->xajax->getJavascript("");
        $this->load->view('welcome_message',$data);
    }
    
    function process_form($a)
    {
    
    $result = "Your name is  panji";
    $name =  'txt_value';
    //$name is param of an "id" of an element and its not a "name" of an element
    $this->objRes->addAssign($name, "value", $result);
    return $this->objRes;

    }
    
    
}



View :

Code:
&lt;? echo $Printjavascript;?&gt;

&lt;form name="ajaxform" id="ajaxform" onsubmit="return false;"&gt;
          This is your name :
          &lt;input type="text" id="txt_value" name="txt_value" size="20"/&gt;
          &lt;input type="submit" value="submit" onclick="xajax_process_form(xajax.getFormValues('ajaxform'));"/&gt;
  &lt;/form&gt;



keep on tryin bro.. Smile



Regards
#7

[eluser]pandjie[/eluser]
Thanks for your "quick" response :lol: ...

This code can work too :

Code:
$objResponse->script("xajax.$('txt_value').value='".$result."';");




Theme © iAndrew 2016 - Forum software by © MyBB