Hi..i am actually trying to do something like this.When a user select a particular option from a dropdown list and click a 'Go' button, a confirm message box will be displayed if the user has selected that particular option.Other options selected will not display that confirm box when the 'Go' button is clicked.Once the user press the ok button on the confirm box,it will proceed to perform other tasks.How do i do that?..I try using the following code but it doesnt really work..the confirm box will always popup everytime the 'Go' button is clicked except for the first time u clicked on it.
<script language=javascript>
function Go()
{
if (<%=drop1.SelectedIndex%> == 1)
confirm("Please select a 'Sort By' field!");
}
</script>
![]() |
-1 |
![]() |
The reason that it works the way you have described is because the first time the page is accessed the if statement will actually read:if (0 == 1)Once the DropDownList has been changed (say to the second item, which results in SelectedIndex equalling 1) the if statement will read:if (1 == 1)If the DropDownList had been changed to the third item the if statement would read:if (2 == 1)The reason for this is that you are trying to mix your client-side and server-side scripting, which won't work.
What you need to do is pass this as the parameter to the Go function and then use the selectedIndex property in the if statement. For example:<select onChange="Go(this)">
function Go (ddl) {
if ( ddl.selectedIndex == 1 ) { ... }
}
Steven Bey
Recursion: see Recursion
![]() |
1 |
![]() |
Hi..tks a lot. i understand what u mean. but what i want is for the user to select the item first followed by clicking a 'Go' button before popping up the confirm message box and not popping up the box on instant change of the selected item.I would appreciate yr guidance again..tks.
![]() |
1 |
![]() |