Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question IF Textbox = value then redirect Help

    OK, my javascript is not that good. So I need your help!

    I need to create a text box that will only work if a certain code is entered. So if 1234 is in the text box and submit is clicked, then it will take you to the site. IF not then it will print "Please enter correct code" next to the submit button.

    Here is what I have so far:


    <input name="txtBox" type="text"/>

    <input name="btnButton" type="button" value="Submit" onclick="return checkValue()" />




    <script type="text/JavaScript">
    function checkValue()
    {
    var secretcode = document.getElementById("txtBox");


    if (secretcode == "1234")
    {
    document.location.href = 'secret.html';
    }
    }
    </script>

    Thank you for your help!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,318
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    Code:
    <input type="text" id ="txtBox" />
    <input type="button" name="btnButton"  value="Submit" onclick="checkValue()" />
    
    <script type="text/JavaScript">
    function checkValue() {
    var secretcode = document.getElementById("txtBox").value;
    if (secretcode == "1234"){
    window.location.href = 'secret.html';
    }
    }
    </script>
    But the security level is zero as anyone can see the secret code simply with View Source.


    Quizmaster: Which 1996 Leonardo di Caprio film was an adaptation of a famous Shakespeare play?
    Contestant: Titanic.

  • Users who have thanked Philip M for this post:

    puraw (12-08-2010)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for your help. Is there a way to use javascript and be secure? Or am I going to have to rewrite this in php or some other language?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,318
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    Quote Originally Posted by puraw View Post
    Thanks for your help. Is there a way to use javascript and be secure? Or am I going to have to rewrite this in php or some other language?
    Javascript is very insecure. Depending on the sophistication of your users and the importance of the material in the site, it is possible to obfuscate/encode the password in such a way that only Javascript experts could decipher it. But anyone who knew how to would crack it in under a minute.

    But not only can someone use View Source to see the password, they can read the "secret" URL as well and just navigate directly to it. So that must be obfuscated/encoded as well.

    It would be best to use server-side scripting.

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you very much. I will look into coding it with php now. This will work as a temporary fix since it is just going to be for a promo page. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •