Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:22:55+00:00 2026-05-31T06:22:55+00:00

I have a login page using jQuery Mobile which contains the following code: <div

  • 0

I have a login page using jQuery Mobile which contains the following code:

  <div id="loginPage" data-role="page" data-theme="a">

    <div data-role="content">

      <div id="alerts"></div>

      <form id="login-form">

        <input type="text" id="username" name="username" value="" placeholder="username or email" />
        <input type="password" id="password" name="password" value="" placeholder="password" />

        <button id="login-button" onClick="userLogin()">Login</button>

      </form>

    </div><!-- /content -->

  </div><!-- /page -->

Here is a part of my javascript that is called when the user clicks the ‘Login’ button. If one of the fields is left blank, I see the following text injected into the #alerts div, but then within a fraction of a second the content has disappeared again.

if (username.length == 0 || password.length == 0) {
  //alert('Please enter your username or email and your password');
  $('#alerts').html('Please enter your username or email and your password.').trigger('create');
}

I also tried this using .append() instead of .html(). Same result with both. I’ve commented out my test alert(), which works when one of the fields is left blank.

What can I do to make sure the content remains on the page once it is injected?

Thank you for any help or insight you can offer! -Mark

Per Jasper’s request, here is all of the javascript that is executed when the ‘Login’ button is clicked:

function userLogin() {
  var username = $("#username").val();
  var password = $("#password").val();

  if (username.length == 0 || password.length == 0) {
    $('#alerts').append('Please enter your username or email and your password.').trigger('create');
  }

  else {
    $.post("services/user-status.php", { type: 'login', username: username, password: password },
      function(data) {
        var response = data.item;
        console.log(response);
        if (response.loggedIn == false) {
          $('#alerts').html('The username/email and password you used did not work. Please try again.').trigger('create');
        }
        else {
          localStorage.userID = response.userID;
          localStorage.username = response.username;
          localStorage.userStatus = 'loggedIn';
          $.mobile.changePage('profile.html');
        }
      },'json');
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:22:56+00:00Added an answer on May 31, 2026 at 6:22 am

    It looks like you need to stop the propagation of the click event from firing for your button. You can do that by returning false in the click event handler:

    HTML —

    <button id="login-button" onClick="return userLogin()">Login</button>
    

    JS —

    function userLogin() {
        ...
        return false;
    }​
    

    Here is a demo: http://jsfiddle.net/BkMEB/3/

    Also, since you are using jQuery, you can bind to the <button> element like this:

    $('#login-button').bind('click', userLogin);
    

    This is the same as putting onClick="return userLogin()" as an attribute of the button but allows you to remove your inline JS.

    Here is a demo: http://jsfiddle.net/BkMEB/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery Address Plugin and I have the following code. $.address.change(function(e) {
My Jquery mobile application has a simple login page through which the user will
Normally we have login page with username, password filed and signin button. Using the
I'm using ASP.NET MVC 2 and have a login page that is secured via
I have created a user login page and am using Forms Authentication. Users are
I have to login into a https web page and download a file using
i have implemented facebook log in using Facebook javascript SDK in Jquery mobile ,
I have a dialog window in my JSP page and its implemented using jQuery.
I have implemented a WebApp using SplitView - http://asyraf9.github.com/jquery-mobile/ - (and that seems to
I have a standard HTML login page, which I would much rather use than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.