0

I want to simulate a mobile app. I have a login in page. Is it possible to validate the form and send the user to another page. I am using a single html page for my mobile app. I do not want to use PHP. What would be the best method to take ? getElementbyID ?

<form id="login" name="login" action="" method="">


<div data-role="fieldcontain">
 <label for="username"></label>
 <input type="email"  name="username" id="username" value="" placeholder="Username" ``required="required"/><br />
 </div>
 <div data-role="fieldcontain">
 <label for="password"></label>
<input type="password" name="password" id="password" value="" placeholder="Password"/><br />
 </div>
 <a  data-role="button" type="submit" name="loginSubmit" id="loginSubmit" placeholder="Login"  />Login</a>

 </form>
  • Do you need something like this: http://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link? – segarci Mar 09 '14 at 23:32
  • I want to vaildate the email and password as required fields and then login to page two.
    did not work
    – user2941458 Mar 09 '14 at 23:43

1 Answers1

0

try this one using javascript

formData = {
    username: $("#username").val(),
    password: $("#password").val()
}
if ($("#username").val() == '') {
    alert("Enter your username");
} else if ($("#password").val() == '') {
    alert("Enter your password");
} else {
    $.ajax({
        type: 'POST',
        contentType: 'application/json',
        url: "https://www.example.com/login.php",
        dataType: "json",
        data: formData,
        success: function(data) {
            //success handler
        },
        error: function(data) {
            //error handler
        }
    });
}
Nurdin
  • 23,382
  • 43
  • 130
  • 308
  • thanks Dato, if i was to change the "url:"https://www.example.com/login.php"," to $mobile.changepage(#pagetwo) how can I set it so that when user press's submit they will be taken to #pagetwo of the single html file ? – user2941458 Mar 10 '14 at 20:08
  • you can't because url link is for authentication purpose. you can put this code in #pagetwo – Nurdin Mar 11 '14 at 00:09