Need a little help with JS

I’m trying to do something similar to what Gii does when inputting a table name - reflect (mirror) that input into another inputfield.

My form is 2 dropdown select lists (single select) which are generated via Table::model()->findall().

What I want to do is take the TEXT value returned from each box and populate a 3rd like so:

Field 3 box: field1Text - field2Text

I can write code to update field3 based on field1 or field2 but not both! Do I need to use append() or prepend() or what? Need a kick in the right direction. Thanks!

What is your code for this…

A little embarrassed - I found (a) solution. This is cool because if you subsequently change the first element it ‘starts over’.

I need to figure out how to alter this a little - when you change the second element it appends an additional second element to the box.



$('#Assignment_stationId').bind('change', function()


	$('#Assignment_assignmentName').val($('#Assignment_stationId :selected').text());


$('#Assignment_templateId').bind('change', function()


	$('#Assignment_assignmentName').val($('#Assignment_assignmentName').val() + ' - ' + ($('#Assignment_templateId :selected').text()));




<div class="form">

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



)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">

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

		<?php echo $form->dropDownList($model, 'stationId', CHtml::listData(Station::model()->findAll(), 'id', 'stationName'), array('prompt' => 'Select Station:'));$form->textField($model,'stationId'); ?>

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


	<div class="row">

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

		<?php echo $form->dropDownList($model, 'templateId', CHtml::listData(Template::model()->findAll(), 'id', 'templateName'), array('prompt' => 'Select Template:'));$form->textField($model,'templateId'); ?>

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



	<div class="row">

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

		<?php echo $form->textField($model,'assignmentName',array('size'=>50,'maxlength'=>50)); ?>

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