如何写一个php代码在组合框值改变时保留文本框中输入的值[已关闭]

mbzjlibv  于 2023-01-29  发布在  PHP
关注(0)|答案(1)|浏览(116)

6小时前关门了。
Improve this question
enter image description herewhen select box in form changes all the values in textboxes disappear

cedebl8k

cedebl8k1#

//Check if below code is helpful 
<?php
if(isset($_POST['combo_box_name'])) {
    $combo_box_value = $_POST['combo_box_name'];
    // Retain textbox values
    $textbox1_value = isset($_POST['textbox1_name']) ? 
    $_POST['textbox1_name'] : "";
    $textbox2_value = isset($_POST['textbox2_name']) ? 
    $_POST['textbox2_name'] : "";
}
?>

<form method="post">
    <select name="combo_box_name" onchange="this.form.submit()">
        <option value="option1" <?php if($combo_box_value == "option1") 
        echo "selected"; ?> >Option 1</option>
        <option value="option2" <?php if($combo_box_value == "option2") 
        echo selected"; ?> >Option 2</option>
    </select>

    <input type="text" name="textbox1_name" value="<?php echo 
    $textbox1_value;?>"/>
    <input type="text" name="textbox2_name" value="<?php echo 
    $textbox2_value;?>"/>

    <input type="submit" value="Submit"/>
</form>

相关问题