简体   繁体   中英

pass selected option value with an id via URL

I'm new to PHP and I'm trying to pass the value of option value in the select through the URL with the id .But I'm having trouble with implementing the logic to send the option value in the URL itself with the id .I know that I can send the value using POST method. But if I use POST method how can I pass id to the model.

This is the code that contains the select options and the URL that I'm trying to pass the parameters.

 <div class="table-responsive" ">
<table class="table">
    <thead class="thead-dark">
    <tr>
        <td>#</td>
        <td>Task</td>
        <td>Status</td>
        <td>Action</td>
    </tr>
    </thead>
    <tbody>
    <?php
    $data = new tasks();
    $set = $data->get();
    foreach ($set as $row) {

        ?>
        <tr>
            <td><?= $row['id'] ?></td>
            <td><?= $row['name'] ?></td>
            <td>
                <select name="status" id="status">
                    <option value=""><?= $row['status'] ?></option>
                    <option value="Completed">Completed</option>
                    <option value="Currently Working">Currently Working</option>
                    <option value="Have To Start">Have To Start</option>
                </select></td>
            <td>
                <a href="task.php?status=<?= $row['status'] ?>&id=<?= $row['id'] ?>" type="submit"  class="btn btn-update" name="update">Update</a>
                <a href="task.php?delete=<?= $row['id'] ?>" type="submit"  class="btn btn-delete" name="delete">Remove</a>
            </td>
        </tr>

    <?php } ?>

    </tbody>
</table>

Any kind of help would be highly appreciated.

you need to use onchange event on select box check here

so in your case it may be

onchange="document.location.replace('task.php?status='+this.value+'&id=<?= $row['id'] ?>');"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM