Welcome Guest, Not a member yet? Register   Sign In
auto complete another edit field based on one input field
#1

[eluser]Unknown[/eluser]
i have browse and got reference about edit form
the another field data will auto fill if i choose data from combobox name
the problem is i want to change the combo box with input form like other, but if change
<select id="formSelect" name="name" class="input-block-level">
&lt;? foreach($contacts as $contact): ?&gt;
<option value="&lt;?=$contact['name']; ?&gt;">&lt;?=$contact['name']; ?&gt;</option>
&lt;? endforeach; ?&gt;
</select>


with
&lt;input type="text" name="name" class="input-block-level" placeholder="name" &gt;"
it will not auto fill another field

please help me with that
below some capture code from my view and controll

view code
Code:
&lt;form id="formEdit" class="well" accept-charset="utf-8"&gt;
<select id="formSelect" name="name" class="input-block-level">
&lt;? foreach($contacts as $contact): ?&gt;
<option value="&lt;?=$contact['name']; ?&gt;">&lt;?=$contact['name']; ?&gt;</option>
&lt;? endforeach; ?&gt;
</select>
&lt;input type="email" name="email" class="input-block-level" placeholder="Email" required maxlength="40" value="&lt;?=$firstcontact['email']?&gt;"&gt;
&lt;input type="text" name="phone" class="input-block-level" placeholder="Phone" required maxlength="15" value="&lt;?=$firstcontact['phone']?&gt;"&gt;
<button type="submit" class="btn btn-warning btn-large">
<i class="icon-pencil icon-white"></i> Edit Contact</button>

controller code
Code:
public function edit()
    {
        $contacts = $this->contact_model->get_names($this->session->userdata('uid'));
        
        if (count($contacts) > 0) {
            $firstcontact = $this->contact_model->get_data(
                $this->session->userdata('uid'), $contacts[0]['name']);
        } else {
            $firstcontact = array('email' => '', 'phone' => '');
        }
        
        $this->load->view('edit', array(
            'contacts' => $contacts,
            'firstcontact' => $firstcontact
        ));
    }
    
    public function edit_contact()
    {
        sleep(1);
        $this->load->library('form_validation');
        $this->form_validation->set_rules('name', 'Name', 'required|max_length[40]|callback_alpha_dash_space');
        $this->form_validation->set_rules('email', 'Email', 'required|max_length[40]|valid_email');
        $this->form_validation->set_rules('phone', 'Phone', 'required|max_length[15]|alpha_numeric');
        
        if ($this->form_validation->run() == FALSE) {
            $message = "<strong>Editing</strong> failed!";
            $this->json_response(FALSE, $message);
        } else {
            $this->contact_model->update($this->input->post('name'), $this->input->post('email'),
                $this->input->post('phone'), $this->session->userdata('uid'));
            
            $message = "<strong>".$this->input->post('name')."</strong> has been edited!";
            $this->json_response(TRUE, $message);
        }




Theme © iAndrew 2016 - Forum software by © MyBB