views:

143

answers:

1

Hi all,i'm trying to create 3 textfield with CI by using form_input. One is for enter price,one is for enter the desire discount value,the last one is for the discounted price which is calculated from price and discount value..How do i achieve it with CI?Thanks a lot..

A: 

Hi Handoyo!

Well I wasn't able to fully understand the question since title says Ajax and in text you have not mentioned any ajax.

Well I'll explain how to use ajax with CodeIgniter. I'll be assuming u use JQuery and CodeIgntier.

Using Ajax with CodeIgniter is fairly simple. All you have to do is call the proper controller from Jquery.

for eg.

<input type="text" name="val1" />
<input type="text" name="val2" />
<input type="text" name="val3" id="val3" />
<input type="button" id="button" />

above is your view code now jquery:

$('#button').click(function(){
$.ajax({
url: 'http://domain/index.php/controller',
...
...
success: function(val){
$('#val3').val(val);
}
});
});

in codeigniter controller you can fetch the values and return result as a number by echoing it.

function controller()
{
 $val1 = $this->input->post('val1');
 $val2 = $this->input->post('val2');
 echo $val1 + $val3;
}

Thats it.

Codemaster Snake
Thanks Codemaster..Suppose for example i want to get val3 value upon entering value in val2.What should i do?Thanks...
handoyo