Welcome Guest, Not a member yet? Register   Sign In
unable to send javascript variable to controller

These are the options available in t_plan table
id    plan_name
--    ---------
4  -  free
5  -  Gold
6  -  Silver
7  -  Platinum

My object is to as user click on an option in the form it will populate the
following input boxes next to select box from the data of t_plan table.

So i store the id of plan in a hidden inputbox 
and send that value to controller so that it can
fetch the corrosponing data from the t_plan table and 
populate the following.


Here is my code(in view)
       $('#plan2_id').val($("#plan2_list option:selected").val());
       var zplan = $('#plan2_id').val();
type: "POST",
url: "<?php echo base_url();?>super_admin/get_plan_value_by_id/+zplan",
data: {"zplan": zplan},
      success: function(data) {
  error: function(e) {

zplan display the correct data which i am sending to my controller:

My Controller

public function get_plan_value_by_id($zplan){
alert(data.email);   = $this->sa_model->select_plan_by_id(zplan);
            echo  alert(data.email);
$data['admin_maincontent'] = $this->load->view('admin/add_employer_form',$data,TRUE);

My Modal

    public function select_plan_by_id($zplan){
$result = $query_result->row();
//echo "<pre>";
        return $result;

But it say "undefined"
or give "error"

The attached form image will clear what i want.

Please help

(This post was last modified: 05-02-2017, 08:28 AM by xenomorph1030.)

Your Ajax call is a bit extraneous when passing zplan as you have it in the URL and as a query parameter. I suggest picking one.

My legitimate suggestion is to study up on Javascript and PHP. You are clearly mixing the two in get_plan_value_by_id(). Once you remove the Javascript from your PHP function and assuming your query works correctly, you will have to return (echo/print in this case) a JSON object (do not load any views). An easy way is to use the built in PHP function json_encode().

Your problem is here:
url: "<?php echo base_url();?>super_admin/get_plan_value_by_id/+zplan"
Should be something like :
url: "<?php echo base_url();?>super_admin/get_plan_value_by_id/" + zplan


I have got this json array from controller


Now i want to display the values in the forms input 

I try this but it does not display the plan_price (999) in the input field

document.getElementById("plan_price").value = data.plan_price; 

Please help

Attached Files Thumbnail(s)

Theme © iAndrew 2016 - Forum software by © MyBB