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 6833889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:02:23+00:00 2026-05-26T23:02:23+00:00

The alert() works fine, but return false does not stop the form being posted

  • 0

The alert() works fine, but return false does not stop the form being posted – any ideas?

<script type="text/javascript">
function form_val() {
    //Check date
    var email=document.getElementById('email').value;
    var passw=document.getElementById('password').value;
    if(email==''||email==null||passw==''||passw==null) {
        alert('Please fill in both fields.');
        return false;
    }  

}
</script>

<form action="userlogin.html" method="post" name="log_form" onsubmit="return form_val();">
    <div data-role="fieldcontain">
        <input type="email" name="email" id="email" value="" placeholder="Email Address" />
        <input type="password" name="password" id="password" value="" placeholder="Password" />
        <div class="ui-grid-a">
        <div class="ui-block-a">
            <button type="submit" name="login" value="" data-theme="c">Sign In</button>
        </div>
        <div class="ui-block-b">
            <br />
            <a href="http://mobile.*****.com/lostpswd.html" rel="external" style="font-size:10px; padding-left:10px;">Forgotten Password?</a>
        </div>
    </div>
</form>
  • 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-26T23:02:24+00:00Added an answer on May 26, 2026 at 11:02 pm

    You’ve tagged your question jquery-mobile but you’re not using jQuery anywhere in the quoted code.

    The code looks right in an old-fashioned DOM0 sort of way (which is okay and should still work except for issues with getElementById on IE7 and earlier). I’d change the checks in form_val a bit:

    function form_val(){
        //Check date
        var email=document.getElementById('email').value;
        var passw=document.getElementById('password').value;
        if(!email || !passw) {
            alert('Please fill in both fields.');
            return false;
        }  
    }
    

    …but the ones you had probably should have worked barring the IE issue listed above or other script errors on the page in code that isn’t shown.

    Here’s how you’d use jQuery (which works around the IE bug for you automatically) for the above:

    jQuery(function($) {
        $("form[name='log_form']").submit(form_val);
    });
    function form_val() {
        if (!$("#email").val() || !$("#password").val()) {
            alert('Please fill in both fields.');
            return false;
        }
    }
    

    …or if you don’t need form_val to be global (avoid global functions where possible, and it doesn’t need to be global just to validate this form):

    jQuery(function($) {
        $("form[name='log_form']").submit(form_val);
        function form_val() {
            if (!$("#email").val() || !$("#password").val()) {
                alert('Please fill in both fields.');
                return false;
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$.post($(this).attr(action), $(this).serialize(), function(json) { alert('red'); AddItemAjax(json); }, json); This works in Chrome but not
i have the following script. everything works fine in ff, safari. But in IE
<form method=post action=/Order/CheckOut/ onSubmit=return Validate()> and then... function Validate() { alert($(#email).val()); return false; }
I have this jQuery which works fine $(li[id^='shop_id']).click( function () { alert(I clicked on
This works : alert(document.getElementById(Container).nodeName); But this doesnt : var CurParent = document.getElementById(Container); alert(CurParent.nodeName); I
Does anyone know why this code doesn't work. This means, the alert is NOT
<script> $(function(){ $('.logger').bind('click',function(){ alert('we will log that the user shared something'); return true; //keep
Here is my simple code, which works fine if called from php or any
This code always works, even in different browsers: function fooCheck() { alert(internalFoo()); // We
Funny thing is that if i delete the comment for alert(data[i].id) the code works.

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.