I need to create a search feature using JavaScript that will trigger a message or pop-up window if users fail to select an option from a dropdown list. The challenge I am facing is that my project involves user controls, which means the dropdown lists are located in a .ascx file while the search function needs to be in a .aspx file. Here is the code snippet I currently have:
function Search()
{
var src_status = createObj("bodyuc_drp_Status").value;
var src_program = createObj("bodyuc_drp_program").value;
if(document.getElementById(src_program).value == 0 && document.getElementById(src_client).value == 0)
{
alert("Please select at least one client or program");
return false;
}
else {
createObj("hdn_search").value = "Search";
return true;
}
}
In the code, '0' represents the index of the '--select one--' option in the dropdown list. The desired notification should only appear if the selected index is 0; otherwise, the search function should proceed based on the user's selection.
The current issue is that the alert message shows up even when a user selects an option other than 'select one.' I'm struggling to understand why this happens. Any insights would be greatly appreciated.
Thank you for your assistance!