doueta6642
2011-08-31 04:39
采纳率: 0%
浏览 31

CakePHP问题:如何从radiobutton获得价值以及如何调用动作?

<div id="rightsidesix" >

    <?php echo '<div class="class_color_title" ><b>'."Polls".'</b></div>'; ?>

    <?php

        echo '<div id="id_color_polls" >';

            echo '<p><b>Which linux distribution do you like most ?</b></p>'.'<br/>';

            $options=array('F'=>'Fedora','U'=>'Ubuntu','D'=>'Debian','O'=>'openSuse','M'=>'Mandriva','T'=>'Other');

            $attributes=array('legend'=>false);

            echo $this->Form->radio('distributions',$options,$attributes);

            echo $this->Form->button('Check',array('id'=>'id_btnpolls'));

        echo '</div>';

        echo '<br/>';

    ?>

</div>      

Should i add these form input/radio buttons in a form ?

After clicking the button it will call jQuery function.

$("#id_btnpolls").click(function(){



    var valCheckedRadio = $('input[name=data[distributions]]:checked').val()

    alert(valCheckedRadio);



    $.ajax({

        type: "POST",

        url: "<?php Router::url(array('controller'=>'posts','action'=>'polls')); ?>,",

        data: "valCheckedRadio="+valCheckedRadio,

        success: function(prm){

            //alert(prm);

            $("#id_color_polls").html(prm);

        }

    });
})

Is this correct way to call an action of a controller ?

        url: "<?php Router::url(array('controller'=>'posts','action'=>'polls')); ?>,",
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutao1171 2011-08-31 05:33
    已采纳
    $("#id_btnpolls").click(function(){
    
    
    
    var valCheckedRadio = $('input[name=data[distributions]]:checked', '#myForm').val()
    
    alert(valCheckedRadio);
    
    
    
    $.ajax({
    
        type: "POST",
    
        url: "<?php $html->url(array('controller'=>'posts','action'=>'polls')); ?>,",
    
        data: "valCheckedRadio="+valCheckedRadio,
    
        success: function(prm){
    
            //alert(prm);
    
            $("#id_color_polls").html(prm);
    
        }
    
      });
    })
    
    打赏 评论
  • duanbi6522 2011-08-31 05:21

    Whatever you've done looks absolutely fine for me. You can use something like this to get a value from radio group.

    $('input[name=radioName]:checked', '#myForm').val()
    

    As per your url part its perfectly fine with cakephp.

    打赏 评论

相关推荐 更多相似问题