ayeng 0 Newbie Poster

Hi, I need help!

I want my textbox value to be change using jquery in cakephp during onchange event of my textbox.

below is my add.ctp code:

<div class="jobs form">
<?php echo $this->Form->create('Job', array('type'=>'file')); ?>
    <fieldset>
        <legend><?php echo __('Add Job'); ?></legend>
    <?php

        echo $this->Html->script('ckeditor/ckeditor');
        date_default_timezone_set('Asia/Manila');
        echo $this->Form->input('users_id');
        echo $this->Form->input('comp_name', array('label' => 'Company Name'));
        echo $this->Form->input('title');
        echo $this->Form->input('category_id');
        echo $this->Form->input('subcategory_id');
        echo $this->Html->image('../', array('width' => '250', 'height' => '120', 'id' => 'UserLogo'));
        echo $this->Form->input('filename', array('type' => 'file', 'label' => 'Logo'));
        echo $this->Form->input('content', array('class' => 'ckeditor'));
        echo $this->Form->input('email');
    ?>
    </fieldset>
    echo $this->Form->submit('Submit');
?>
<?php
$this->Js->get('#JobUsersId')->event('change',
$this->Js->request(array(
    'controller'=>'users',
    'action'=>'getEmail'
), array(
    'update'=>'#JobEmail',
    'async' => true,
    'method' => 'POST',
    'dataExpression'=>true,
    'data'=> $this->Js->serializeForm(array(
            'isForm' => true,
            'inline' => true
        ))
))
);
?>

my controllers code:

public function getEmail() {
        if( $this->request->is('ajax') ) {
            $usrId = $this->request->data['Job']['users_id'];
            $data = $this->User->find('first', array('conditions' => array('User.id' => $usrId), 'fields' => array('User.email'), 'recursive' => -1));
            $this->set('JobEmail', $data);
            $this->layout = 'ajax';
        }
    }

my get_Email.ctp code:

<?php foreach ($JobEmail as $email): ?>
    <input value="<?php echo $email['email']; ?>">
<?php endforeach; ?>

I wonder why it's not working with above using textbox.

I tried set my form to this - echo $this->Form->input('email', array('type'='select'));

and in my get_Email.ctp to this - <?php foreach ($JobEmail as $email): ?> <option value="<?php echo $email['email']; ?>"><?php echo $email['email']; ?></option> <?php endforeach; ?>

and its working fine. The problem is when my input is not set type to 'select', the value will not display but set type to 'select', it is working then.

By the way, I am using Cakephp v2.4.6

Any help is much appreciated.

Thanks for ur support

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.