JavaScript change to DropDownList.SelectedIndex not submitted
Posted
by Bellfalasch
on Stack Overflow
See other posts from Stack Overflow
or by Bellfalasch
Published on 2010-05-26T12:09:35Z
Indexed on
2010/05/26
12:41 UTC
Read the original article
Hit count: 233
Hi
So, I have a form to submit fighters. You write his/her name, country, and then the team they fight for + the team's country.
When you start typing the name I have constructed my own Ajax AutoCompleter. It will find existing fighters that might match.
When you click on one of the suggestions it will populate up to four fields depending on existing data in the database. If you're lucky the fighter already exists with information on country, team, and the team's country.
The problems starts when submitting. The JavaScript follows and just get's the id of the country to select (also the value of the select-option), and the select-element itself.
function dropdownSelect(value, element) {
var dropdown = document.getElementById(element);
for (var i = 0; i < dropdown.options.length; i++) {
if (dropdown.options[i].value == value) {
dropdown.options[i].selected = true;
return true;
}
}
}
When submitting the ASP.NET-code halt's and says that my country-field is null. So my JavaScript-change of selected field couldn't be read by ASP.NET.
Is this a limitation of how ASP.NET works? Or a limitation of my skills? ;P
© Stack Overflow or respective owner