开发者

HTML Forms & PHP: Can I process input on a dropdown form without a submit button (instantly as selected)?

I have a drop-down where users can select a couple of options. Can I get the option value right away and process an action without a submit button?

Example, a drop-down that has the option delete for a photo. As soon as a person selects delete in that list it will delete the photo.

开发者_开发知识库Can I test the $_POST['delete'] and delete the photo?

Thanks!


You can with JavaScript and AJAX. Otherwise you need to use a regular old POST with a submit button.

It is possible to force a form submit with JavaScript, as if the button had been pressed, but this is not good for usability.


Example of what I think you're going for with Javascript:

<?php
    if (isset($_POST['action'])){
        if ($_POST['action']=='Delete'){
            // Code for deleting photo goes here
        }

    }
?>

<html>
<head></head>

<body>

<form method="POST" name="PhotoOptions"> 
<select name="action" onChange="document.forms['PhotoOptions'].submit()">  
    <option>Save</option>
    <option>Delete</option>
</select>

</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜