I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.
In a view, I have two dropdownlist which loads same values from a table in the base.
I want create an event that delete the item selected in the DropDwonList 1 from the DropDownList 2.
This is the code :
<%:Html.Label("Poste :")%><%: Html.DropDownListFor(model => model.SelectedPoste, Model.PostesItems, new { @id = "poste" })%>
<%:Html.Label("Poste Suivant :")%><%: Html.DropDownListFor(model => model.PosteSuivantSelected, Model.NextPS, new { @id = "dd" })%>
So basing on the code above, when the item is selected in 'Poste',,,its similair should be deleted from 'Poste Suivant'.
This is what I try but it's not worked :
function test3() {
var dd = document.getElementById('dd');
var posteElement = document.getElementById('poste');
var currentIndexP = posteElement.selectedIndex;
var currentIndexD = dd.selectedIndex;
if (currentIndexP == currentIndexD) dd.removeChild(dd[currentIndex]);
}
I think the problem is : because I didn't define 'test3()' in the dropdownlist.