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 4 of 4

Thread: coupon

  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts

    coupon

    Tried the search...got results...then page can't be displayed connection problems.

    Anyway, I've been out of the loop for 5 years and thought I could code my own JS coupon code. Turns out I'm rusty and need a tad bit of help.

    Where did I go wrong?

    Thanks

    Code:
    <script>
    function checkit() {
    if (document.getElementById('coupon').value == 'z28')
        window.location='http://google.com';
        }
       
    else  {
         window.location='http://yahoo.com';
         }
    </script>
    Code:
    <form>
    <input type="text" size="11" name="coupon" id="coupon" value="Coupon Code" onFocus="this.value='';">
    <input type="button" value="Send" onClick="checkit(this);">
    </form>
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You forgot the opening curly bracket after the if and the closing bracket for the function

    And: It should be window.location.href (window.location will work also, but it is not the "official" way).
    Code:
    function checkit() {
    if (document.getElementById('coupon').value == 'z28') {
        window.location='http://google.com';
        }
       
    else  {
         window.location='http://yahoo.com';
         }
    }
    Btw, the Javascript console of your trust should have easily shown you the problem with a syntax error
    Last edited by devnull69; 04-29-2013 at 07:33 AM.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    You have left out a couple of braces.

    Code:
    <script type = "text/javascript">
    
    function checkit() {
    if (document.getElementById('coupon').value == 'z28') {
    window.location.href='http://www.google.com';
    }
    else  {
    window.location.href='http://www.yahoo.com';
    }
    }
    </script>
    
    <form>
    <input type="text" size="11" name="coupon" id="coupon" value="Coupon Code" onfocus='this.value="" '>
    <input type="button" value="Send" onclick="checkit();">
    </form>
    But the user can see the correct coupon code simply with View Source. At the very least you should obfuscate it.

    Quizmaster: CO2 is the chemical symbol for which gas?
    Contestant: Petrol

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks. I got it when the site was down. This may account for the search links broken. Anyway, it works. If I were to obfuscate, I'd include it. I'm not really trying very hard to hide it. Thanks
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">


  •  

    Posting Permissions

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