View Single Post
Old 01-19-2012, 11:30 PM   PM User | #1
shivam1992
New to the CF scene

 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shivam1992 is an unknown quantity at this point
Need Help Finding out problem with my code?! Please help!

This Program is basically prompting the user to enter information such as name,address,province,city,country etc and then validating the information,
I have two functions, one called promptInformation which takes in the name,address,province,city,country and postal code, this function basically prompts the user information, my other function validate information has the same parameters as prompt information, this function basically checks to see if the name,address,province,city,country and postal code are entered and if they are then it checks the country variable and if the country variable is canada it displays the name,address,province,city,country and postal code in red, and if its US it displays the information in blue.

My problem is when the user does enter the correct information it isnt going into the else block? why is that? I changed the null to "" one time and it did go into the else block but it didnt go into the check for the country, so what is the problem here?

Here is my code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


</head>

<body>

<script type="text/javascript">
	
	var name;
	var country;
	var province;
	var city;
	var streetAddress;
	var postalCode;
	
	promptInformation(name,country,streetAddress,postalCode,city,province);
	while(validation(name,country,streetAddress,postalCode,city,province)==0)
	{
		
		promptInformation(name,country,streetAddress,postalCode,city,province);
		
	}
	
	function validation(name,country,streetAddress,postalCode,city,province)
	{
    	
    	if(name==null ||name=="" || country==null||country=="" ||streetAddress==null||streetAddress=="" ||postalCode==null||postalCode=="" ||province==null||province=="")
    	{
			return 0;
    	}
    	else
    	{
			alert("blah");
    		if (country.toUpperCase()=="CANADA")
        	{
				
        		document.write("<font color=red>"+name+"<br>"+streetAddress+"<br>"+city+","+province+","+country+"</font>");
				return 1;
        	}
			else if(country.toUpperCase()=="US")
			{
				document.write("<font color=blue>"+name+"<br>"+streetAddress+"<br>"+city+","+province+","+country+"</font>");
				return 1;
			}
			else
			{
				return 0;
			}
		}
       


}
	function promptInformation(name,country,streetAddress,postalCode,city,province)
	{
		name=null;
		country=null;
		province=null;
		city=null;
		streetAddress=null;
		postalCode=null;
		 name=prompt("Please enter your name");
		 country=prompt("Please enter your country");
		 province=prompt("Please enter your province");
		 city=prompt("Please enter your city");
		 streetAddress=prompt("Please enter your street address");
		 postalCode=prompt("Please enter your postal code");
	
	
	}
</script>



</body>
</html>

Last edited by shivam1992; 01-20-2012 at 12:07 AM..
shivam1992 is offline   Reply With Quote