Yii Framework Forum: Help Need How To Save Dropdown Selected Value? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Help Need How To Save Dropdown Selected Value? Rate Topic: -----

#1 User is offline   Attique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-November 13

Posted 25 November 2013 - 06:37 AM

I have many drop downs list like this code
<?php

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

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

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

echo $form->error($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

0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,062
  • Joined: 16-February 11
  • Location:Japan

Posted 25 November 2013 - 07:34 AM

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.yiiframew...endent-dropdown
0

#3 User is offline   Attique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-November 13

Posted 25 November 2013 - 11:23 PM

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 Attached File  yii 2.png (84.79K)
Number of downloads: 24
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,062
  • Joined: 16-February 11
  • Location:Japan

Posted 26 November 2013 - 01:07 AM

Oh, no, I don't want to see the picture of your editor. :(
Please post your code.

Guidelines For Posting In This Forum
0

#5 User is offline   Attique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-November 13

Posted 26 November 2013 - 01:34 AM

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 ?????
//$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'); 
  
?>

0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,062
  • Joined: 16-February 11
  • Location:Japan

Posted 26 November 2013 - 05:47 AM

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.
0

#7 User is offline   Attique 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-November 13

Posted 27 November 2013 - 06:22 AM

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>


	 <?
	// }


?>

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users