Hi,
On my aspx page I have a asp:dropdown list that is populated from the database with a listing of Chapters and their corresponding ID fields. The page also contains a datagrid that is being populated on the basis of the Chapters dropdown list selection. I am calling the dropdown list ddlChapter. DDL chapter also has one blank element that does not contain a chapter. Selecting the blank element does not populate the datagrid with any values.
What I would like to do is to add a javascript (or otherwise) confirmation window to the dropdown list. When a user makes a selection other than the blank item I would like to display a custom message notifying them of which selection they are about to make and asking them if they would like to proceed.
If the user selects to continue the selectedIndexChange event should fire -- populating my datagrid. If the user selects to cancel the index change the even should not execute.
Can anyone help me with this code. I have tried using
ddlChapter.Attributes.Add("onchange", "return ConfirmApply();")
This code does call my javascript method, but the datagrid is never repopulated -- ie the selectedIndexChange event never fires no matter what the choice is when this attribute is added to the control. My javascript ConfirmApply function is as follows. At the moment it just returns the value of the selecteditem in the dropdown list.
function ConfirmApply() { var doc = document.forms[0]; var myValue = doc.ddlChapter.options[doc.ddlChapter.selectedIndex].value; alert(myValue); return false; }
Does anyone have any ideas on how I can make this form function so that I can display a confimation dialogue on the ddlChapter indexChange event but still repopulate the datagrid if the users selection is to proceed?
Any advice is appreciated! Thanks.