セレクトを選択し内容を変更

http://www.tagindex.com/javascript/form/comp2b.html
設計図

bootstrap.ctp

[php]
<!–bootstrap.ctp–>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
[/php]

View

[php]
<?php echo $this->BootstrapForm->input(‘lecture_id’,array(‘options’=>$lecture_id)); ?>
<div id="ajaxsnum"></div>
<?php
$this -> Html -> script( ‘jquery-1.7.2.min’, array( ‘inline’ => false ) );
?>
<?php
$this->Html->scriptStart(array(‘inline’=>false));
?>
$(function(){
$("#UserLectureId").change(function() {
$.post(
"<?php echo $this->html->url(‘/Users/ajaxsnum’) ?>",
{lecture_id : $(‘#UserLectureId option:selected’).val()}, //valを取る textも取れるよ
function(data){
$("#ajaxsnum").html(data);
}
);
});
});
<?php
$this->Html->scriptEnd();
?>
[/php]

View(ajaxsnum.ctp)

[php]
<?php
echo $this->BootstrapForm->input(‘Number’, array(‘label’ => ‘numbers’,’multiple’ => ‘checkbox’));
?>
<div>
<?php echo $this->BootstrapForm->submit(__(‘Submit’));?> //Submitをこっちにしたら保存出来たよ
</div>
[/php]

Controler

[php]
public $helpers = array(‘TwitterBootstrap.BootstrapHtml’, ‘TwitterBootstrap.BootstrapForm’, ‘TwitterBootstrap.BootstrapPaginator’,’Js’,’Html’);
//——————————————————————————–
// ajaxソースコード
//——————————————————————————–
public function ajaxsnum(){
$this->layout = ‘ajax’;
//debug($this->request);
$numbers = $this->User->Number->find(‘list’, array(
//’conditions’=>array(‘lecture_id’ => $this->request->data[‘lecture_id’]),
));
$this->set(compact(‘numbers’));
}
[/php]

edit.ctp

[php]
$data = $this->User->findById($id);
$numbers = $this->User->Number->find(‘list’, array(
‘conditions’=>array(‘Number.lecture_id =’ =>$data[‘User’][‘lecture_id’]),
));
$this->set(compact(‘numbers’));
[/php]

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です