如何在按钮单击事件后更改文本框、select 框和复选框的值?
how to change the text box,select box and check box value after the button click event?
<html>
<body>
<form method="post">
Name :<input type = "text" name= "name" value = "<?php echo $_GET["name"];?>">
salary :<input type = "number" name = "salary" value = "<?php echo $_GET["salary"]?>">
<input type = "submit" value = "submit">
</form>
</body>
</html>
在上面的代码中,name 和 salary 文本框从 url 中获取值。一旦我们更改姓名或薪水文本框的值,并且如果我们提交表单,将调用 "post" 方法并将姓名薪水值存储在 table 中。
现在我的查询是提交表单后,我希望在各自的文本框中显示姓名和薪水的新值,以类似的方式如何在 [=17= 中实现] 框、单选框和复选框。
将您的表单方法从 POST 更改为 GET,这会将变量存储在查询字符串中并使您的 $_GET
变量可以访问它们。
两种方式:
将方法改为get
:<form method="get">
将您回显的值更改为:
<?php echo isset($_POST["name"])?$_POST["name"]:$_GET["name"];?>
对于select:
<select name = "department">
<?php $output = $connection->get_department();
if($output["status"] == 1){
$array = $output["array"];
foreach($array as $res){?>
<option value = "<?php echo $res["id"];?>">
<?php echo $res["name"];
if(isset($_POST["name"]) && $_POST["name"] == $res["name"]){
echo " selected";
}?>
</option>
<?php
}
}
?>
</select>
<html>
<body>
<form method="post">
Name :<input type = "text" name= "name" value = "<?php echo $_GET["name"];?>">
salary :<input type = "number" name = "salary" value = "<?php echo $_GET["salary"]?>">
<input type = "submit" value = "submit">
</form>
</body>
</html>
在上面的代码中,name 和 salary 文本框从 url 中获取值。一旦我们更改姓名或薪水文本框的值,并且如果我们提交表单,将调用 "post" 方法并将姓名薪水值存储在 table 中。
现在我的查询是提交表单后,我希望在各自的文本框中显示姓名和薪水的新值,以类似的方式如何在 [=17= 中实现] 框、单选框和复选框。
将您的表单方法从 POST 更改为 GET,这会将变量存储在查询字符串中并使您的 $_GET
变量可以访问它们。
两种方式:
将方法改为
get
:<form method="get">
将您回显的值更改为:
<?php echo isset($_POST["name"])?$_POST["name"]:$_GET["name"];?>
对于select:
<select name = "department">
<?php $output = $connection->get_department();
if($output["status"] == 1){
$array = $output["array"];
foreach($array as $res){?>
<option value = "<?php echo $res["id"];?>">
<?php echo $res["name"];
if(isset($_POST["name"]) && $_POST["name"] == $res["name"]){
echo " selected";
}?>
</option>
<?php
}
}
?>
</select>