Ilia
Ilia

Reputation: 17

Passing a value from jquery to php to another view

I am getting the value of a checkbox using jquery. How can I pass that value in another view? I want to use it to access data from the DB. This is how far I've got.

Script

<script type="text/javascript" charset="utf-8">
        $(function(){
            $('#btnClick').click(function(){
                var val = [];
                $(':checkbox:checked').each(function(i){
                val[i] = $(this).val();
                });
            });
        });
//SOME CODE
<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'submission-form',
        'enableAjaxValidation'=>false,
        'action'=>Yii::app()->createUrl('submission/create'),
        'htmlOptions'=>array('enctype'=>'multipart/form-data'),
    )); 
//SOME CODE
<?php echo CHtml::submitButton('Next', array('id'=>'btnClick','name'=>'btnClick',)); ?>

Upvotes: 0

Views: 153

Answers (1)

Vishal Sharma
Vishal Sharma

Reputation: 1372

You can use ajax.

<script type="text/javascript" charset="utf-8">
    $(function(){
        $('#btnClick').click(function(){
            var val = [];
            $(':checkbox:checked').each(function(i){
            val[i] = $(this).val();
             $.ajax({
               type: "POST",
               url: "some.php",
               data: { Value: val[i] }
                   })
               .done(function( msg ) {
                alert( "Data Saved: " + msg );
                 });
            });
        });
    });
//SOME CODE
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'submission-form',
    'enableAjaxValidation'=>false,
    'action'=>Yii::app()->createUrl('submission/create'),
    'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); 
//SOME CODE
<?php echo CHtml::submitButton('Next', array('id'=>'btnClick','name'=>'btnClick',)); ?>

And In Some.php Get that value in variable like

<?php $Selected_Value = $_POST['Value']; ?>

And Perform any database query here.

Upvotes: 1

Related Questions