Welcome Guest, Not a member yet? Register   Sign In
Getting value from a javascript variable into a php variable???
#1

[eluser]Roy MJ[/eluser]
Hi,

Can anyone help me in telling me how to get a javascript variable to transfer its value to a variable in php.??? I used a javascript for a multiple select box and the multiple selection is working fine. But i dunno how to get the value from the javascript variable which stores the result.

My controller looks like this :

Code:
function add(){
            $data['tourcategory'] = $this->Tour_packages_model->select_category();
            $data['destination'] = $this->Tour_packages_model->select_destination();
            //if data submitted ' '
            $this->load->plugin('js_calendar');
            if($this->input->post('Submit')){
            $config = array(
                     array('field'   => 'destination', 'label'   => 'Destination', 'rules'   => '')      
                    );
            $this->form_validation->set_rules($config);
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('admin/tour_packages/add',$data);
            }
            else{
                    $this->Tour_packages_model->save('Add', $data);
                    redirect('/admin/tour_packages');
                }
        }else{
                $this->load->view('admin/tour_packages/add',$data);
        }    
    }


My model page looks like this :

Code:
function save($type='',$field='')
    {
            switch($type){
                case 'Add':
                $data = array(
                'destination' => $this->input->post('destination')
                                            
                );
                                        
            $this->db->insert('tour_package', $data);
            break;
     }

And my view looks like this :

Code:
<head>

</head>

<table border=0>
            <tr>
            <td valign="top" width=175>
            <label for="departure">Destinations:* </label>
            <br>
            <select name="available"  style="width:150px" size=10>
            &lt;?php
            foreach($destination as $row)
            {
            ?&gt;
            <option value=&lt;?php echo $row->destination?&gt;>&lt;?php echo $row->destination?&gt;
            &lt;?php
            }
            ?&gt;
            </select>
            </td>
            <td valign="top">
            Your Choices:
            <br>
            <select multiple name="destination" style="width:150px;" size="10">
            </select>
            </td>
            </tr>
            <tr>
            <td colspan=2 height=10>
            &lt;input type="button" value="Remove"&gt;
            &lt;input type="button" value="Get Selected Values"&gt;
            </td>
            </td>
            </tr>
            </table>


         <button value="Send" name="Submit" id="submit-go" type="submit">Add</button>

I am not able to post the javascript linked with it. This forum is showing one error.

The save part of the script is shown below:






[/code]




The final result is stored in the variable strValues i think. But i cannot find a way as to get the result into a variable outside the script so that the i can add the data obtained into the database. Please help..


Messages In This Thread
Getting value from a javascript variable into a php variable??? - by El Forum - 01-10-2011, 10:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB