Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-23-2012, 10:57 AM   PM User | #1
pilotdude647
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
pilotdude647 is an unknown quantity at this point
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");
	}
}
pilotdude647 is offline   Reply With Quote
Old 10-23-2012, 11:35 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,035
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
pilotdude647 (10-23-2012)
Reply

Bookmarks

Tags
alert, javascript, prompt, verify

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:44 AM.


Advertisement
Log in to turn off these ads.