简体   繁体   English

如何将JavaScript值检入Rails变量

[英]How to check JavaScripts values into a rails variable

I have JavaScripts variables which I got as username and password, I want to check them out if they are okay then show me a new link or new page if not then show me a text. 我有用用户名和密码获取的JavaScripts变量,我想检查它们是否还可以,然后显示一个新链接或新页面,否则显示一个文本。

!DOCTYPE html>
<html>
<head>
<script>
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
}
if (x == "n/a_17") 
{
window.location="http://cmpt470.csil.sfu.ca:8017/welcome/index ";
}
</script>
</head>

<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateF$
User Name: <input type="text" name="username">
Password: <input type="text" name="fname">
<input type="submit" value="Submit"> 
</form>

<% if x == "n/a_17 -%>
password is correct
 <a href="/posts/new"> posts </a>
<% end -%>

</body>
</html>

From your comments, if you're only trying to do an authentication form with Rails, you should check out first the Rails Tutorial , Chapter 7 is about building an authentication form. 根据您的评论,如果您仅尝试使用Rails编写身份验证表单,则应首先查看Rails教程第7章是关于构建身份验证表单的信息。

You might also want to check the Rails Guides . 您可能还需要检查Rails指南

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

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