PopUp box if Value in Textbox equals a certain value

I have an empty textbox and a ‘Save’ button in a cart. What I would like to do is if a user enters in a correct coupon code in the textbox and clicks the ‘Save’ button then a popup will come on the screen with a message saying, “You have entered in the correct value. You win a free box of chocolates!” If they enter in an incorrect code, then the popup will say something else. I figured Javascript would be the best way to go, but I’m not sure how to code it. Right now, my form code is like this:

<input type="text" name="coupon_code" size="20" maxlength="50" class="coupon"
 alt="<?php echo $this->coupon_text ?>" value="<?php echo $this->coupon_text; ?>"
 onblur="if(this.value=='') this.value='<?php echo $this->coupon_text; ?>';"
 onfocus="if(this.value=='<?php echo $this->coupon_text; ?>') this.value='';" />

The textbox is not required to be filled in, so it is optional.

Thank you.

I’d say that JavaScript is the worst solution, for someone can just inspect the code to find out what the coupon text is, which can be as easy as right-clicking on the input field and choosing “inspect element”


IMHO JavaScript is the way to go - but NOT as in your example.

Client-side JavaScript should only be used to better the user’s experience eg. “you entered an invalid email address, please try again”
Never for security or sensitive / private information.

JavaScript as in AJAX

If there is insufficient time between the AJAX returning and the user clicking submit, you could have code make a “you may have won, please wait a short while to find out” type of message,
Then when the AJAX returns the results of the check, show that.

Thank you for the suggestion. I guess I’ll head towards that direction then.