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

  • Home
  • SEARCH
  • 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 6380781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:18:43+00:00 2026-05-25T02:18:43+00:00

Everything is going fine jst a little bit mistake only when i press enter

  • 0

Everything is going fine jst a little bit mistake only

when i press enter it will send the value througn $.post(). after success the page refreshes why so

and if i use some other keycode it will remain same value inserted but no refresh

<script>
    $(document).ready(function(){
    $('#newNumber').focus();
    $('#newNumber').keypress(function(e){
            var code=e.keyCode;
            //alert(code);
            if(code==61)
                {
            var nno=$('#newNumber').val();
            $('#load').show();
            if(nno=="")
                {
                    $('#load').hide();
                    $('#alertBox').show();
                    $('#newNumber').focus();
                    $('#alertBox').html("<div class=error><span id=alerttext class='alerttext'>Empty Field</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                    $('#close').click(function(){$('#alertBox').fadeOut(2000);});

            }
            else
            {
                $.post("NumberAction/addAction.php",$('#contentForm').serialize(),function(result){
                    if(result=="yes")
                        {
                            $('#load').hide();
                            $('#alertBox').show();
                           $('#alertBox').html("<div class=warning><span id=alerttext class='alerttext'>Already Exists</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                           $('#newNumber').val("");
                           $('#newNumber').focus();
                           $('#close').click(function(){$('#alertBox').fadeOut(2000);});
                    }
                    else if(result=="done")
                    {
                        $('#load').hide();
                        $('#alertBox').show();
                        $('#alertBox').html("<div class=success><span id=alerttext class='alerttext'>New number is added</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                           $('#newNumber').val("");
                           $('#newNumber').focus();
                           $('#close').click(function(){$('#alertBox').fadeOut(2000);});
                    }
                    else if(result=="error")
                    {
                        $('#load').hide();
                        $('#alertBox').show();
                        $('#alertBox').html("<div class=error><span id=alerttext class='alerttext'>Error in adding</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                           $('#newNumber').val("");
                           $('#newNumber').focus();
                           $('#close').click(function(){$('#alertBox').fadeOut(2000);});
                    }
                })
            }
            }
        })
    })
</script>

Now values is going but when i press enter it will send the value but also it will refresh the page so that i am not able to use the Enter key code

  • 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-25T02:18:44+00:00Added an answer on May 25, 2026 at 2:18 am

    My guess is that you are detecting pressed key somewhere inside FORM tag and by pressing enter you not only send the ajax using $.post, but also tell the browser to submit the form regular way so the page is reloaded. To prevent this, you can do one of two things:

    1) Prevent submission of the form, using:

    $("#yourform").submit(function(e) {e.preventDefault()});
    

    2) After doing “$.post(“NumberAction/addAction.php”,….” do return false;

    <script>
    $(document).ready(function(){
    $('#newNumber').focus();
    $('#newNumber').keypress(function(e){
            var code=e.keyCode;
            //alert(code);
            if(code==61)
                {
            var nno=$('#newNumber').val();
            $('#load').show();
            if(nno=="")
                {
                    $('#load').hide();
                    $('#alertBox').show();
                    $('#newNumber').focus();
                    $('#alertBox').html("<div class=error><span id=alerttext class='alerttext'>Empty Field</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                    $('#close').click(function(){$('#alertBox').fadeOut(2000);});
    
            }
            else
            {
                $.post("NumberAction/addAction.php",$('#contentForm').serialize(),function(result){
                    if(result=="yes")
                        {
                            $('#load').hide();
                            $('#alertBox').show();
                           $('#alertBox').html("<div class=warning><span id=alerttext class='alerttext'>Already Exists</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                           $('#newNumber').val("");
                           $('#newNumber').focus();
                           $('#close').click(function(){$('#alertBox').fadeOut(2000);});
                    }
                    else if(result=="done")
                    {
                        $('#load').hide();
                        $('#alertBox').show();
                        $('#alertBox').html("<div class=success><span id=alerttext class='alerttext'>New number is added</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                           $('#newNumber').val("");
                           $('#newNumber').focus();
                           $('#close').click(function(){$('#alertBox').fadeOut(2000);});
                    }
                    else if(result=="error")
                    {
                        $('#load').hide();
                        $('#alertBox').show();
                        $('#alertBox').html("<div class=error><span id=alerttext class='alerttext'>Error in adding</span><div id=close class='close'><img src='images/close.png'/></div></div>");
                           $('#newNumber').val("");
                           $('#newNumber').focus();
                           $('#close').click(function(){$('#alertBox').fadeOut(2000);});
                    }
                })
                // return false to prevent regular form submission
                return false;
            }
            }
        })
    })
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We started some overseas merge replication 1 year ago and everything is going fine
I am trying to load an NSMutableArray with UIImageViews. Everything is going fine with
whats going on is everything is loading just fine url is deigned.sytes.net except for
I just downloaded MVC and I am going through a tutorial. Everything goes fine
I am making a screen capturing application and everything is going fine. All I
I have a problem that whenever I'm inserting data using coredata, everything's going fine.
I'm building my first Qt app using Qt Creator, and everything was going fine
I'm not sure what's going on here. Using MiniMagick 3.3, everything was working fine
I have setup a git server using gitosis and everything was going fine. I
So I'm working on a project and everything's going fine until I try to

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.