<div id="background">
<div class="form-group">
<label for="usr" style="position:fixed;margin-top:180px;margin-left:900px;"><u>Account ID</u>:</label>
<input type="text" placeholder="Enter your ID in here" class="form-control" id="usr" style="position:absolute;width:350px;margin-top:205px;margin-left:900px;">
</div>
<div class="form-group">
<label for="pwd" style="position:fixed;margin-top:230px;margin-left:900px;"><u>PIN</u>:</label>
<input type="password" placeholder="Enter your PIN in here" class="form-control" id="pwd" style="position:absolute;width:350px;margin-top:255px;margin-left:900px;">
<button type="submit" onClick="process_Login()" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:fixed;margin-left:1040px;margin-top:310px;width:100px;">Login</button>
<button type="submit" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:absolute;margin-left:1150px;margin-top:310px;width:100px;">Sign Up</button>
</div>
</div>
我在使用此代码时遇到了一些问题,我在网上做了ATM视觉。我想将数据从HTML文件传输到PHP文件,我知道我必须使用&#34; form&#34;但在这种情况下我不知道如何使用它,我也使用&#34; script&#34;解决用户输入的错误值。
<script>
function process_Login() {
var c = document.getElementById("usr").value;
var d = document.getElementById("pwd").value;
if (c.length == 0) {
alert("ERROR: Your ID account is NULL");
} else if (isNaN(c)) {
alert("ERROR: Your ID must be number");
}
}
</script>
我该怎么做才能解决它?
答案 0 :(得分:1)
如果您正在制作表单,则会将其发布到PHP脚本中。 您的输入需要具有名称属性,即
<form action="myPHPLogin.php" method="post">
<input type="text" placeholder="Do this.." name="username">
<button type="submit">submit</button>
</form>
在PHP脚本上,您可以使用$ _POST ['username']等访问您的字段。
答案 1 :(得分:0)
你应该创建这样的表格:
<form action="file.php" method="post" onsubmit="return process_login()">
<!-- your form code here -->
</for>
记得在<input type="submit">
代码上删除onClick处理程序
而不是你的javascript代码:
<script type="text/javascript">
function process_login(){
var c = document.getElementById("usr").value;
var d = document.getElementById("pwd").value;
if(c.length==0){
alert("ERROR: Your ID account is NULL");
return false;
} else if(isNaN(c)){
alert("ERROR: Your ID must be number");
return false;
}
return true;
}
</script>
答案 2 :(得分:0)
"S4"
<div id="background">
<div class="form-group">
<form method="post" id="dataForm">
<label for="usr" style="position:fixed;margin-top:180px;margin-left:900px;"><u>Account ID</u>:</label>
<input type="text" placeholder="Enter your ID in here" class="form-control" id="usr" name="user" style="position:absolute;width:350px;margin-top:205px;margin-left:900px;">
</div>
<div class="form-group">
<label for="pwd" style="position:fixed;margin-top:230px;margin-left:900px;"><u>PIN</u>:</label>
<input type="password" placeholder="Enter your PIN in here" class="form-control" id="pwd" name="pass" style="position:absolute;width:350px;margin-top:255px;margin-left:900px;">
<button type="button" onClick="process_Login()" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:fixed;margin-left:1040px;margin-top:310px;width:100px;">Login</button>
<button type="button" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:absolute;margin-left:1150px;margin-top:310px;width:100px;">Sign Up</button>
</form>
</div>
}
//your javscript
function process_Login() {
var c = document.getElementById("usr").value;
var d = document.getElementById("pwd").value;
if (c.length == 0) {
alert("ERROR: Your ID account is NULL");
} else if (isNaN(c)) {
alert("ERROR: Your ID must be number");
}
$.ajax({url:"your php page.php",type:'POST',data:$("#dataForm").serialize(),success: function(data){
if(data==0){alert("No data Added");}
}});