Hi,I have simple login form, where fields are validated by javascript. I don't now why the below code is not working.
my html and js code:
<head>
<script type="text/javascript">
function handleLogin() {
var u = $("#username").val();
var p = $("#password").val();
if(u=="a" && p=="a")
{
window.location="/Site/site.html";
}
else
{
alert("Fail");
}
}
</script>
</head>
<li dojoType="dojox.mobile.ListItem">
<input dojoType="dojox.mobile.app.TextBox" placeHolder="username" type="text" id="username" name="username" />
</li>
<li dojoType="dojox.mobile.ListItem">
<input dojoType="dojox.mobile.app.TextBox" placeHolder="password" type="password" id="password" name="password" />
</li>
<li dojoType="dojox.mobile.ListItem">
<input dojoType="dojox.mobile.Button" onclick="handleLogin()" type="button" id="submit" name="submit" value="Login"/>
</li>
When I click on the submit button nothings happening.
Thanks
dreamweiver
5,9922 gold badges27 silver badges39 bronze badges
asked May 8, 2013 at 13:12
user1031034
8661 gold badge15 silver badges38 bronze badges
-
1Are you getting any error in firebug console ?dreamweiver– dreamweiver2013年05月08日 13:14:32 +00:00Commented May 8, 2013 at 13:14
-
2Did you actually load jQuery?Ja͢ck– Ja͢ck2013年05月08日 13:14:36 +00:00Commented May 8, 2013 at 13:14
-
1do you get any error ? Are you sure the function isn't executed ?Laurent S.– Laurent S.2013年05月08日 13:14:52 +00:00Commented May 8, 2013 at 13:14
-
works fine for me: jsfiddle.net/EnkrTjbabey– jbabey2013年05月08日 13:17:00 +00:00Commented May 8, 2013 at 13:17
-
I didn't get any errors.user1031034– user10310342013年05月08日 13:18:30 +00:00Commented May 8, 2013 at 13:18
2 Answers 2
You didn't load the jQuery library. But you can do without it:
var u = document.getElementById('username').value,
p = document.getElementById('password').value;
Changing the page is done with location.href instead of window.location:
location.href = '/Site/site.html';
answered May 8, 2013 at 13:15
Ja͢ck
174k39 gold badges269 silver badges317 bronze badges
Sign up to request clarification or add additional context in comments.
7 Comments
user1031034
I don't want load jQuery and I forgot when I wrote this. This solution without jQuery doesn't work
Ja͢ck
@user1031034 Oh, I've corrected a typo; that was probably it.
Ja͢ck
@dreamweiver
Node.val() is not a function in pure JS and getElementById() doesn't take a selector.user1031034
Now it's work :) but only when I have incorrect data in form. But when I have corect it's do nothing. It's good redirect to other site in javascript (without jquery).
window.location="/Site/site.html";dreamweiver
@Jack: Thanks for the correction jack, typical mistake when you are addicted to jQuery lib :)
|
try to import
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
answered May 8, 2013 at 13:17
PSR
40.4k43 gold badges115 silver badges154 bronze badges
Comments
default