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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Add verification to prompt box

    Hi,

    I am making an very basic interactive webpage.
    I have created a prompt box and wish to add a verification to this with an alert attached so that if the enter the right word a popup appears saying so and also if they don't but it won't work.
    I get the prompt to enter the text but no alert.

    Can anyone help me thank you.

    HTML:
    Code:
    <a onclick="yellow3()">Click here bro</a>
    Javascript:
    Code:
    function yellow3()
    {
    	var name=prompt("Please enter the colour yellow", "Colour");
    	if(name==yellow || name==Yellow || name==YELLOW)
    	{
    		alert("You have correctly entered yellow");
    	}
    	else
    	{
    		alert("You have incorrectly entered yellow");
    	}
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    The literal must be in quotes:-

    Code:
    if(name.toLowerCase()=="yellow") {  // "yellow", "Yellow", YeLLow" etc.
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    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.

  • Users who have thanked Philip M for this post:

    pilotdude647 (10-23-2012)


  •  

    Tags for this Thread

    Posting Permissions

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