简体   繁体   English

具有两个值的输入字段

[英]Input field with two value

I have two input fields as this: 我有两个输入字段,如下所示:

  1. input type="hidden" name="action" value="login">
  2. input type="hidden" name="action" value="admin_login">

I have two separate login forms, which I want to become one 我有两个单独的登录表单,我想成为其中一个

I've searched for the solution on internet and it seems that it is better to let in tho form the value of "login", so that normal users login using their credentials, and then do some javascript in the page translated as IF username === adminX then this. 我已经在Internet上搜索了该解决方案,似乎最好输入“ login”的值,以便普通用户使用其凭据登录,然后在页面中执行一些javascript转换为IF username === adminX然后这个。 form value="admin_login" . 形式为value="admin_login"

Any help on how to accomplish this, I don't know much of javascript 任何有关如何完成此操作的帮助,我对JavaScript的了解都不多

Using java script you can do this by 使用Java脚本,您可以通过

<script>
function check_login() {
if (userType==admin){
 Myform.value="admin_login";}
else{
 Myform.value="user";
}
}
</script>
<input type="submit" onclick="check_login()">

I think the best way to do this by having single form for both user but now depend on server side how you handle it.like 我认为最好的方法是为两个用户使用单一表单,但现在取决于服务器端如何处理它。

if(userType==admin_login) {
//show admin permissions for result page
}
else{
hide all admin permissions and show only given permission for normal user for result page
}

later: done it like this, because next day the version from comment is not working anymore..boh 后来:这样做是因为第二天注释的版本不再起作用..boh

<form method="POST" action="index.php">
<input type="text" placeholder="Username" id="username" onBlur="myFunction()" name="username" value="">
<input type="password" placeholder="Password" name="password">
<button type="submit" name="action" id="log" value="login">SIGN UP</button>
</form>

and javascript: 和javascript:

<script type="text/javascript">
  function myFunction(){
    var username = document.getElementById("username").value;
    if(username == 'admin'){
    document.getElementById("log").value='admin_login';
    }else{
    document.getElementById("log").value='login';
    }
  }
</script>

Hope it helps someone in the future. 希望它对将来的人有所帮助。 Thank you! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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