开发者

CakePHP question: How can i get value from radiobutton and how can i call an action?

<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'));

        ec开发者_开发百科ho '</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')); ?>,",


$("#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);

    }

  });
})


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜