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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:17:57+00:00 2026-05-31T00:17:57+00:00

Haven’t been coding in a bit, but took on a project for a friend.

  • 0

Haven’t been coding in a bit, but took on a project for a friend. Basically, I need a 1 input form that checks for a 4 digit code. If the code is correct (is one of the 2 or 3 possible correct codes), it proceeds to a new page, if it’s not it doesn’t submit, and displays an error. It doesn’t have to be very pretty. Looking for a jquery solution, and any push in the right direction would be appreciated. I’m very rusty.

<form name="codeForm" action="" method="get">
     <input name="yourCode" type="text" id="yourCode"/>
    <input name="submit" type="submit" value="Go" id="code_input_submit" />

    <div id="message"><p></p>
     </div><!--end message-->

</form>

<div id="btn"></div>

and my jquery is along the lines of the following:

$(document).ready(function () {
var code1 = "7816";
var code2 = "1226";

$('#btn').click(function() {
var value = $('#yourCode').val();

    if (value == code1){                                             // go to site 'abc.com/'code1;
    }
      else if (value == code2){                                         //go to site 'abc.com/'code2;
    }
    else{                                      $('#message').html('your code is wrong');
    }
});

});
  • 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-31T00:17:58+00:00Added an answer on May 31, 2026 at 12:17 am

    If this is what it seams to be, a validation requirement and you’re actually thinking of storing the data client side: No, no, no!

    Your “entry-pins” will be in plain sight of every single user trying to log on.

    You should always authenticate server side.

    1. store the keys on server (database or file, whatever suits you)
    2. client makes a request to server via post
    3. Server accepts or denies client request
    

    For example, submit the form to the server-side page authenticate.php

    And PHP file will check if user is good to go or not.

    <?php
    // very simple and not really secure server-side auth script
    $codes = {1234, 5678, 9012};
    $valid_user = false; // all users are invalid until otherwise
    
    $user_inserted_code = (int) $_POST['key'];
    if(in_array($user_inserted_code, $codes)) {
        $valid_user = true;
    }
    
    if($valid_user==true)
         header("Location: http://example.com/authenticated");
    else
         header("Location: http://example.com/failled_auth");
    ?>
    

    If you really don’t need security and the codes you’re refering to are static and something in the likes of (ie) department codes… growing on your example you can just use a simple switch:

    $(document).ready(function () {
        var code1 = "7816";
        var code2 = "1226";
    
        $('#btn').click(function() {
            var value = $('#yourCode').val();
    
            switch(value) {
                case 7816: window.location = "http://google.com/"; break;
                case 1226: window.location = "http://yahoo.com"; break;
                default: $('#message').html('your code is wrong');
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haven't seen anything, but I have seen that you can create albums in the
I haven't been able to find much about this but am I the only
I haven't tried that yet, but I assume that I would have to disable
I haven't studied design patterns, but I'm willing to bet that there is one
Haven't seen this feature anywhere else. I know that the 32nd bit is used
Haven't fired up reflector to look at the difference but would one expect to
Haven't seen anything about it here but it seems to solve one of the
I haven't seen any questions relating to GNU autoconf/automake builds, but I'm hoping at
I haven't done a lot of .NET programming, but I've examined a few of
I haven't found any documentation on this or seen this done before, but is

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.