Jump to content

Recommended Posts

Hi everybody,

 

I am just learning to use the Confirm Box feature in Javascript. I have tried to add it onto HTML form's submit buttons and checkboxes without problem. But when I add it to a HTML drop down list the behavior is a bit different and unexpected. My code looks like this:

 

<select name='mychoice' onclick='return confirm("Are you sure?");'>

<option value='1' selected='selected'>Apple</option>

<option value='2'>Orange</option>

<option value='3'>Lemon</option>

</select>

 

When I select one choice (whether it is Apple or Orange or Lemon), the Confirm Box pops up as expected. The problem is, when I press Cancel, the original choice will not appear, unlike checkboxes. In other words, pressing OK and Cancel will lead to the same result. Is my code wrong, or is there any simple way to make the original choice re-appear when Cancel is pressed?

 

Thanks,

pengi.

Edited by pengi

Thank you very much. But inside the if-else, what should I do so that the original selection can be shown? I have searched the Internet and seems a solution is __doPostBack(), but the following code still does not work:

 

<select id="z" name="sy" onChange="if (confirm('Are you sure?')) {alert('1');} else {__doPostBack('z','');}">
<option value='1' selected='selected'>Apple</option>
<option value='2'>Orange</option>
<option value='3'>Lemon</option>
</select>

 

Am I doing something wrong in the else part?

 

Thanks,

pengi.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.