Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:23:08+00:00 2026-06-03T23:23:08+00:00

I have created a simple drop-down menu in PHP: <td> Privilege: </td> <td><select name=privilege>

  • 0

I have created a simple drop-down menu in PHP:

<td> Privilege: </td>
<td><select name="privilege">
<?php 
    $position_list = array(
                1 => "Chair", 
                2 => "SACA",
                5 => "Faculty",
                0 => "Disable User",
                );
    foreach ($position_list as $priv_id=>$position) {
    echo "<option value= \"{$priv_id}\"";
            if ($priv_id == $sel_user['privilege']) {
                 echo " selected"; 
            }
            echo ">{$position}</option>";   
    }   
?></td></select>        
        </tr>       
        </tr>

I am wondering if it is possible to include some Javascript. So, when the user selects “Disable User”, a message saying “are you sure you want to disable this user?” pops up.
Thanks in advance for any suggestions!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:23:10+00:00Added an answer on June 3, 2026 at 11:23 pm

    The problem here is not displaying the alert – that’s fairly simple – but keeping track of the value the select element used to have. After all, it wouldn’t be much use if the user clicked “no” and the user was disabled anyway.

    In order to do this, I suggest the easiest thing to do would be to use a hidden input element to store the original value. You can then refer to the to set the options back correctly.

    Something like this (HTML structure corrected here, please pay attention 😉 ):

    <td>Privilege:</td>
    <td>
      <!-- note the onchange event -->
      <select name="privilege" onchange="checkDisable(this);">
    <?php 
    
        // Define the options
        $position_list = array(
          1 => "Chair", 
          2 => "SACA",
          5 => "Faculty",
          0 => "Disable User",
        );
    
        // Create the list
        foreach ($position_list as $priv_id=>$position) {
          echo "<option value= \"{$priv_id}\"";
          if ($priv_id == $sel_user['privilege']) {
            echo " selected=\"selected\""; 
          }
          echo ">{$position}</option>";   
        }   
    
    ?></select>
      <input type="hidden" id="privilege_old_val" value="<?php echo $sel_user['privilege']; ?>" />
      <script type="text/javascript">
        function checkDisable(element) {
    
          // Firstly check if the user selected the disable option, then get them to confirm it
          if (element.options[element.selectedIndex].value == 0 && !confirm("Are you sure you want to disable this user?")) {
            // If they didn't confirm it, loop the options...
            for (var i = 0; i < element.options.length; i++) {
              // Find the option with the old value...
              if (element.options[i].value == document.getElementById('privilege_old_val').value) {
                // ...and set the select back to that option
                element.selectedIndex = i;
              } // if
            } // for
          } // if
    
          // Update the input that tracks the old value with the current value
          document.getElementById('privilege_old_val').value = element.options[element.selectedIndex].value;
    
        }
      </script>
    </td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple drop down menu, with functions in it. And then
How to manually create Friendly URLs? (PHP) So I have created simple php file
So I created a simple menu for a small project I have. When people
I have a page with several multiselect drop-down menus. Each menu has a general
I have number of drop down menu's which gets called with a onClick event
I have a 3-level deep, unordered list I'm styling to create a drop-down menu
Created a very simple HTML/CSS drop down navigation using nested unordered lists. Works great
Could someone help me on this, I have created simple web services using axis2
I am new to Repository concept and get some questions. I have created simple
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.