gpt4 book ai didi

javascript - 如何将单选按钮与输入文本字段绑定(bind)?

转载 作者:行者123 更新时间:2023-11-30 14:00:57 25 4
gpt4 key购买 nike

这是员工的注册表单。如果员工是临时的还是永久的,他必须签到一个单选按钮。如果是临时的,他应该填写输入的契约(Contract)号,如果是临时的,他应该填写雇佣日期。我怎样才能将单选按钮与输入绑定(bind),这样他就不能“交叉完成”,例如,如果他是临时的,就填写招聘日期。我想让他只有在按下那个特定的单选按钮时才能填写每个输入。

PHP 代码:

<?php include 'dbconfig.php';?>
<?php header('Content-Type: text/html; charset=utf-8');?>
<!DOCTYPE HTML PUCLIC "-//W3C//DTDHTML
4.0 Transitional//EN"><HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="logintest.css">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</HEAD>
<button class="btn" TYPE="submit" name="goback" onclick="window.location.href='login.php'">Go Back </button>

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
if(isset($_POST['submit']))
{
$sql = "INSERT INTO employee (empID,EFirst,ELast,username, passcode)
VALUES ('".$_POST["empID"]."','".$_POST["EFirst"]."','".$_POST["ELast"]."','".$_POST["username"]."','".$_POST["passcode"]."')";

$result = mysqli_query($conn,$sql);
$answer=$_POST['kind'];
if($answer='permament'){
$sql1 = "INSERT INTO permament_employee (empID,Hiring_Date) VALUES ('".$_POST["empID"]."','".$_POST["date"]."')";
$result1 = mysqli_query($conn,$sql1);
}

if ($answer='temporary'){
$sql2= "INSERT INTO temporary_employee(empID) VALUES ('".$_POST["empID"]."')";
$result2 = mysqli_query($conn,$sql2);
}
echo "<script> location.replace('login.php') </script>";
}
?>

<FORM METHOD="post" ACTION="">
<div class="input-group">
<label>id</label>
<INPUT TYPE="text" name="empID" SIZE="30" required>
</div>
<div class="input-group">
<label>First Name</label>
<INPUT TYPE="text" name="EFirst" SIZE="30" required>
</div>
<div class="input-group">
<label>Last Name</label>
<INPUT TYPE="text" name="ELast" SIZE="30" required>
</div>
<div class="input-group">
<label>username</label>
<INPUT TYPE="text" name="username" SIZE="30" required>
</div>
<div class="input-group">
<label>password</label>
<INPUT TYPE="password" name="passcode" SIZE="30" required>
</div>
<div class="input-group">
<div class="some-class">
<label> Permament <input type="radio" name="kind" value="permament" id="permament" required> <br> <input type="date" name="date" value="date" id="date" required> <br> </label>
<label> Temporary <input type="radio" name="kind" value="temporary" id="temporary" required> <br> <input type="number" name="ContractNr" value="ContractNr" id="ContractNr" placeholder="Contract Number" required> <br> </label>
</div>
</div>
<br>
<br>
<br>
<br>

<button class="btn" TYPE="submit" name="submit">Submit Info </button>
<button class="btn" TYPE="reset" name="Reset">Reset </button>
</FORM>

</HTML>

最佳答案

你需要javascript。您必须在单选按钮上绑定(bind)“更改”事件,并根据单选按钮选择的值设置输入的可见性。

关于javascript - 如何将单选按钮与输入文本字段绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56313925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com