Help Need How To Save Dropdown Selected Value?

[b]I have many drop downs list like this code

<?php

&#036;records = Month::model()-&gt;findAll();





 &#036;list = CHtml::listData(&#036;records, 'bhu', 'bhu');





echo &#036;form-&gt;dropDownList(&#036;model,'bhu', &#036;list, array('prompt'=&gt;'Select name')); 





 echo &#036;form-&gt;error(&#036;model,'bhu'); 

?>

But i want to make dependent i want to save selected value in any variable and shows them but if i echo $records or $ list they just show word (ARRAY) not full array i just want to save selected value in any variable so i pass that value into another dropdown please help i m stuck here more than 1 week please help i will waiting for any one help[/b]

Hi Attique, welcome to the forum.

Please show us the minimized version of your view script and controller code to get a help.

Are you trying to implement a dependent dropdown?

Did you read this wiki?

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown

yes i read this topic but i cant understand i show u my view and cotroller code

Actually i make my controller ,model,and views through crude but on index page i redirect my own view so i do nothing in my crud controller i just put my above code in my view its working fine it fetches data from database also saving value in database from dropdown but i have another drop drown which i want to make dependent on first drop down 4908

yii 2.png

Oh, no, I don’t want to see the picture of your editor. :(

Please post your code.

Guidelines For Posting In This Forum

I make crud of tehsil table And on crud index page i redirect my own page its working fine get value from database and also send but i want to make a dependent dropdown i want to save selected drop down value and pass to other next drop down


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(


	'id'=>'Tehsil',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

)); ?>


<div class="row"style=" background-color:#FFF5EE">

        <?php echo $form->labelEx($model,'date'); ?>

        <?php //echo $form->textField($model,'start_date_time'); ?>

        <?php         

Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');		

        $this->widget('CJuiDateTimePicker',array(

                'language'=>'',

                'model'=>$model,                               

                'attribute'=>'date',

                'mode'=>'datetime',                     

                'options'=>array(),                    

                'htmlOptions'=>array('readonly'=>true) 

        ));                             

        ?> 

        <?php echo $form->error($model,'date'); ?>

</div>

		</br>

		

		

		<table style=" background-color:#FFF5EE">

		<tr>

		<td>

<h5>Tehsil</h5>


 <?php


    $records = Month::model()->findAll();


     $list = CHtml::listData($records, 'name', 'name');

 

	echo $form->dropDownList($model,'name', $list, (array('prompt'=>'Select name'))); 


	 echo $form->error($model,'name'); 


  

?>


 

	</td><td><h5>union Council/ward</h5>

 <?php

//$name="name = '$list' ";       i want to pass here above drop down selected value i tried like this  but                                                 it just show ARRAy without value and indexes <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />??

//$name ="$records";

//echo $name;

//exit();

//$records = Month::model()->findAll($name);





$records = Month::model()->findAllBySql(('SELECT * from month where name=name'),'id', 'name');


    $list = CHtml::listData($records, 'union', 'union');

 

     echo $form->dropDownList($model,'unionname', $list, array('prompt'=>'Select name')); 


     echo $form->error($model,'unionname');

 

?></td></td><td><h5> Month</h5>


 <?php


    $records = Month::model()->findAll();


     $list = CHtml::listData($records, 'month', 'month');

 

	echo $form->dropDownList($model,'month', $list, array('prompt'=>'Select name')); 


	 echo $form->error($model,'month'); 

  

?>

A dependent dropdown works like the following:

  1. Server side … PHP generates the initial page. It has 2 dropdowns. One is filled with options, and the other may be empty at this moment. The page also has a javascript to handle the following action in the client side. And the page is sent to the user’s browser.

  2. Client side … The user selects an item in the 1st dropdown. This action causes the javascript to send back the selected item to the server via ajax call.

  3. Server side … PHP gets the selected item and generates the content of the 2nd dropdown according to the selection. The content is send to the user’s browser via ajax response.

  4. Client side … The javascript receives the response and updates the content of the 2nd dropdown.

You can not pass the selected value of the 1st dropdown to the 2nd one directly in one shot as you are trying to do in your view script.

Thanks 4 replying will u please help me little more i stuck on the place how to include new page in xmlhttp through URL i tried like this but not


<script type="text/javascript" src="http://ajax.googleapis.com/

ajax/libs/jquery/1.4.2/jquery.min.js"></script>


<script type="text/javascript">





function getXMLHttpRequest() {

var request = false;

try {


            request = new XMLHttpRequest();


      } catch(err1) {


      try {


            var request = new ActiveXObject("Microsoft.XMLHTTP");


      } catch(err2) {


            try {


                  var request = new ActiveXObject("Msxml2.XMLHTTP");


            } catch(err3) {


                  request = false;


            }


      }


      }


        return request;


      }

	  

	  

  

	  

	  

function get_unioncouncil(tehsil_id)

{


xmlhttp = getXMLHttpRequest();

var tehsilCode = tehsil_id;

//url= '../site/getuc.php';

url = "index.php?r=sitecontroller/getuc.php";      [b]Stuck here i want to send my request to  my new page getuc in views/site[/b]

alert(url);

xmlhttp.onreadystatechange=function()

{  

//alert('before');

if (xmlhttp.readyState==4 && xmlhttp.status==200){


var word= xmlhttp.responseText;

alert(word);

document.getElementById('union').innerHTML=word;




}

}

xmlhttp.open('GET', url, true);

xmlhttp.send(null);


}




</script>




<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(


	'id'=>'Tehsil',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

)); ?>

My getuc page code is




<?php


$connection=Yii::app()->db;





//$distcode= $_REQUEST["d"];




$sql="SELECT  * from Month where name='Jalalpur' ";

$command=$connection->createCommand($sql);


 $result=$command->query(); 

echo "<option value=''>-----Select-----</option>";

foreach ($command->query() as $row) {

    //now we can access row columns as object properties:

     ?>




	 <option value="1">abc</option>




	 <?

	// }




?>