Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo Change in DropDown List

Status
Not open for further replies.

livezone

MIS
Jan 17, 2003
81
CA
Hi,
I have a drop down list using Select and option tag in HTML.
When some one change the selection in the drop down list, I want give them a warning the selection has been changed, Are you Sure, If they select Ok the change should happen but it they select cancel the change should not happend.
I tried the following code on "onchange=return changestatus();" event of the select but it gives the warning message but it will still retain the new selected value no matter what button u pressed. How I can achive this via javascript?

function changestatus()
{
result = false;

res = confirm ("Are you sure to change the order status!")
if ( res == true )
result= true;

return result;

}
 
I would store the current selectedIndex (0 by default I guess) in a javascript variable. Rather than returning true or false etc, have the changestatus() function set the selectedIndex to the number in the variable if the user chooses NO... otherwise set the number in the variable to be the new selectedIndex.

Cheers,
Jeff


[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
you'll have to capture the old value of the drop down and say

if (res != true){
//set the index back to the old value
}

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top