2

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
6
  • 1
    Are you getting any error in firebug console ? Commented May 8, 2013 at 13:14
  • 2
    Did you actually load jQuery? Commented May 8, 2013 at 13:14
  • 1
    do you get any error ? Are you sure the function isn't executed ? Commented May 8, 2013 at 13:14
  • works fine for me: jsfiddle.net/EnkrT Commented May 8, 2013 at 13:17
  • I didn't get any errors. Commented May 8, 2013 at 13:18

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

7 Comments

I don't want load jQuery and I forgot when I wrote this. This solution without jQuery doesn't work
@user1031034 Oh, I've corrected a typo; that was probably it.
@dreamweiver Node.val() is not a function in pure JS and getElementById() doesn't take a selector.
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";
@Jack: Thanks for the correction jack, typical mistake when you are addicted to jQuery lib :)
|
1

try to import

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
answered May 8, 2013 at 13:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.