dropdownlist

I have one drop down list and one drop down with multi select both have connected with same table means shows the same value, when I select item in drop down list: i want that particular item to be disappear in dropdown with multi select box, how to do it… Is there anything like we need to create widget for this, I tried but not success please help me

Please someone Reply :(

I don’t think this is a Yii question, but here is one quick solution:




<html>

<head>

<script src="jq.js" type="text/javascript"></script>

<script>

function change (val)

{

	$("#second option[value='"+val+"']").remove();

}

</SCRIPT>

</head>

<body>

<select id="first" onchange='change(this.value)'>

	<option value="">select val</option>

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

	<option value="2">val 2</option>

	<option value="3">val 3</option>

</select>


<select id="second" multiple>

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

	<option value="2">val 2</option>

	<option value="3">val 3</option>

</select>

</body>

</html>



Just include jQuery library and will work.

thank u vary much, but in this approach data from the second dropdown getting deleted and finaly there is no data, actually when i select data from one dropdown then that data should remove from other DD and again if I select another data from first DD the previous data shoud appear and the newly selected data should remove.

You own me a beer. ;D

I suggest you to look in jQuery documentation or just Google your question (which is faster solution). :)




<html>

<head>

<script src="jq.js" type="text/javascript"></script>

<script>

function change (val)

{

	var value;

	$("#second").empty();

	$("#first option").each(function()

	{

		value = $(this).val();

		if (value != '' && value != val)

			$("#second").append(new Option($(this+ "option[value='"+value+"']").text(), value, true, false));;

	});

}

</SCRIPT>

</head>

<body>

<select id="first" style="width: 100px;" onchange='change(this.value)'>

        <option value="">select val</option>

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

        <option value="2">val 2</option>

        <option value="3">val 3</option>

</select>


<select id="second" style="width: 100px; height: 80px;" multiple>

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

        <option value="2">val 2</option>

        <option value="3">val 3</option>

</select>

</body>

</html>



PS - I’m not sure if this is best example, but sounds tricky for me. ;D

I just remove options in second dropdown and add ALL options from first, except selected one. :)

<?php

Yii::app()->clientScript->registerScript(‘regfunction’, "

$(’#ContentTerm_term_id’).change(function(){

  termId=&#036;(this).val();


    &#036;('#ContentTerm_sec_term_id').empty();


    &#036;('#ContentTerm_term_id option').each(function()


    {


            value = &#036;(this).val();


            if (value &#33;= '' &amp;&amp; value &#33;= termId)


                    &#036;('#ContentTerm_sec_term_id').append(new Option(&#036;('#ContentTerm_term_id option[value=&#092;&quot;'+value+'&#092;&quot;]').text(), value, true, false));


    });

}).change();

");

?>

this is how I used your code. Thank you very much :)

I have a similar problem but for visibility reasons I have to use Yii. What is my problem:

I have a drop down list with Categories and above that, I want to load the subcategories of the selected category of the first dropdown. Can this happen only with Yii?