[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