Hi everyone! I am new in Web Programming.

I want in my ComboBox to pop up a question everytime a user changes the combo box. It will ask, "Are you sure you want to update" then if the user clicks on yes it will be redirected to another page and if no it will just stay on the same page but the selected value of the combobox will be = "Please select". Is that possible?

Thank you in advance! :)

what you are after is a confirm box (http://www.w3schools.com/js/js_popup.asp):

<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button!");
if (r==true)
  {
  alert("You pressed OK!");
  }
else
  {
  alert("You pressed Cancel!");
  document.getElementById("confirmThis").value = " "; 
  }
}
</script>
</head>
<body>

<select onchange="show_confirm()" name="confirmThis" id="confirmThis">
<option value=" ">Please Select</option>
<option value="opt1">Option 1</option>
<option value="opt2">Option 2</option>
</select>
</body>
</html>

See if you can get what you are after incorporating that. It does not give yes/no but provides the same functionality. You could use the prompt box so they enter yes or no, but I would hate that as a user, plus you have to "catch" a lot of different user input possibilities.

Hi there! Thanks for your quick response!

It works perfectly! But I want something that every time the user clicks on the cancel button the value selected on this combo box will become "Please Select". Is that possible? :)

Sure, that would be in the "else" of the function:

document.getElementById("confirmThis").value = " ";

added to example above in previous post.

Sure, that would be in the "else" of the function:

document.getElementById("confirmThis").value = " ";

added to example above in previous post.

Hi there, It doesn't work. Maybe I got something wrong.

Let me show you my code:

<select name='access' onChange='validation()'>
<option value=' '>Please select...</option>
<option name=admin value=admin>Admin</option>
<option name=member value=member> Member </option>
<option name=trustee value=trustee> Trustee </option>
</select>

<script type='text/javascript'> 
function validation(){
  if(confirm('Are you sure you want to update the membership access?')){
    myForm.submit()
  }else{
   document.getElementById('access').value = ' ';
  }
}
</script>

By the way, I got it! I just forgot the id tag on my combobox.
Thank you very much! You made my day! :)

Great, glad I could help!

Be sure to mark thread as solved. It's also appreciated if you bump up the answer post a rating (the up arrow under the 'permalink') ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.