javascript - Click a button to change the text of text input -
i have part of code in codeigniter controller named 'ajaxcalls' :
public function show_contact_persons($client_id) { $data['contact_persons'] = $this->common_model->select_records('ci_contact_persons', 'client_id', $client_id); //dump($data); function echoarray ($array) { foreach ($array $key => $value) { if ( true == is_array($value) ) { echoarray($value); } else { if ($key == 'contact_person_name') { echo '<input type="button" value="'.$value.'" onclick="changecontact(987)" /><br />'; } } } } echoarray($data); }
and js part @ page calling php file :
function changecontact(contact_name) { document.getelementbyid('contact_person').value = contact_name; }
i put number '987' in example because code works numbers. when put text inside bracket, or want :
onclick="changecontact('.$value.')"
then script doesn't work. numbers. should change make work strings?
you close.
use instead :
onclick="changecontact("'.$value.'")"
whats happening js rendering changecontact(stringvalue);
expecting defined variable.
adding quotations pass function string render : changecontact("stringvalue");
Comments
Post a Comment