0

I have a dropdown menu containing a list of articles. I want to be able to select an option from the dropdown and press a submit button to initiate the deletion of the article.

Right now articles are deleted when selecting an option from the dropdown, not great usability.

    <form action="delete.php" method="get">
    <select onchange="this.form.submit();" name="id">
       <?php foreach ($articles as $article){ ?>
              <option value="<?php echo $article['article_id']; ?>">
         <?php echo $article ['article_title']; ?></option>
     <?php } ?>
</select>
    </form>
1
  • 4
    That's because you have 'onchange="this.form.submit();' in there.. Commented Oct 9, 2013 at 22:20

1 Answer 1

5

Just remove the JavaScript (onchange) and add a submit input:

<form action="delete.php" method="get">
  <select name="id">
   <?php foreach ($articles as $article){ ?>
      <option value="<?php echo $article['article_id']; ?>">
   <?php echo $article ['article_title']; ?></option>
 <?php } ?>
  </select>
  <input type="submit" value="Delete">
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

A simple solution for a novice. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.