Go Back   oOple.com Forums > General > The PlayGround

Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Question Anyone care to help me debug my crappy JavaScript please?

I have to produce a webpage that uses a while{} to ensure that a valid password is entered into a prompt box. Valid passwords include atleast 6 characters, include a @ and begin with the number 0.

Any ideas?

Thanks in advance!!

Code:
<html>
<head>

<script language = "JavaScript">

//Declare and initilise variables
	var intIncludesAt = 0;
	var strPassword = prompt("Please enter a valid password","");
	var intFirstChar;
	var intValidPassword = 0;
	var strCharCheck;

	function validatePassword()
	{
		while(intValidPassword == 0)
		{ 	
			intFirstChar = parseInt(strPassword.charAt(0));
		
			for (intCount=0; intCount<strPassword.length; intCount++)
			{
				if(strPassword.charAt(intCounter) == @)
				{
					intIncludesAt = 1;
				}
			}
		
		if (strPassword.length >= 6 && intintFirstChar == 0 && intIncludesAt == 1)
		{
			intValidPassword = 1;
		}
	}

</script>

</head>

<body>

<input type="button" value="Click here to validate your password" name="cmdValidatePassword" onclick = "validatePassword()">
</body>

</html>
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #2  
Old 09-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Default

So anyways...

This is where im at now:

Code:
<script language = "JavaScript">

//Declare and initilise variables
	var intIncludesAt = 0; //Changes to 1 if an @ sign is found
	var intFirstChar; //First character of the password
	var intValidPassword = 0; 
	var intIncludesAt = 0;

	function validatePassword()
	{
		var strPassword = prompt("Please enter a valid password","");
		
		while(intValidPassword == 0)
		{ 	
			intFirstChar = parseInt(strPassword.charAt(0));
		
			for (intCount = 0; intCount < strPassword.length; intCount ++)
			{
				if(strPassword.charAt(intCount) == "@")
				{
					intIncludesAt = 1;
				}
			}
		
			if (strPassword.length >= 6 && intIncludesAt == 1 && intFirstChar == 0) 
			{
				intValidPassword = 1;
			}
		}			
		
		if (intValidPassword = 1);
			alert("Your password is valid!")
	}
</script>
The problem im getting now is that if I enter any password at all it says that the password is valid...but if I enter nothing and press the button it slows IE8 and shows an error relating to IE8 :/
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #3  
Old 09-05-2009
markwilliamson2001's Avatar
markwilliamson2001 markwilliamson2001 is offline
Mad Member
 
Join Date: Apr 2006
Location: Ledbury, Herefordshire
Posts: 1,889
Send a message via MSN to markwilliamson2001
Default

I think that this is proof that IE8 is "not ready yet"...typical of any microsoft product when it is actually released! Have you tried it with IE7/Firefox 3/Safari etc etc? Does it work in these?

Worth a shot: If you want a quick way of trying out IE7, you need to look at Virtual PC 2007 from MS. Its a free download, and will let you run a seperate XP OS at the same time as your host OS. Might be worth getting hold of some extra RAM which you can assign to the Virtual OS, as it will slow your machine down a bit.
HTH
Mark
__________________
:: AE B5MCE - SP 7.5 v3.0 Brushless Motor - Reedy Shorty Lipo - Savox Servo - Spektrum Rx ::
:: Paint By Turnip Paint ::
Reply With Quote
  #4  
Old 10-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Default

Cheers for that Mark! Sounds like you've been in my shoes before then? What area do you work in then?
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #5  
Old 10-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Default

Right, just need one piece of advice if anyone is able to help??

When I run the above code, and enter a VALID password it shows the alert as below, however, if the password is NOT valid the code just seems to get lost and then I have to close IE.

Does anyone know how I can get past
Code:
if (intValidPassword = 1);
			alert("Your password is valid!")
and then back to the top if the password is invalid?

Thanks

Code:
<script language = "JavaScript">


	function validatePassword()
	{
		//Declare and initilise variables
		var intIncludesAt = 0; //Changes to 1 if an @ sign is found
		var intValidPassword = 0; 
		var intIncludesAt = 0;
		var strPassword = prompt("Please enter a valid password","");
		var intFirstChar = parseInt(strPassword.charAt(0)); //First character of the password
		
		while(intValidPassword == 0)
		{ 	
			for (intCount = 0; intCount < strPassword.length; intCount ++)
			{
				if(strPassword.charAt(intCount) == "@")
				{
					intIncludesAt = 1;
				}
			}
		
			if (strPassword.length >= 6 && intIncludesAt == 1 && intFirstChar == 0) 
			{
				intValidPassword = 1;
			}
		}			
		
		if (intValidPassword = 1);
			alert("Your password is valid!")
	}
</script>
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #6  
Old 10-05-2009
Hairy Spider's Avatar
Hairy Spider Hairy Spider is offline
Senior Member
 
Join Date: Mar 2007
Location: Ashford, Kent
Posts: 497
Default

Under 'fail' conditions, your while loop is not getting any new information upon which to re-evaluate the situation. Once a fail, always a fail and that is not IE8's fault. Moving 1 line will cure the problem.

Regards,
Jon.
__________________
Faversham Off-Road Cake Club
Cake In... Speed Out!
www.forcc.co.uk

Reply With Quote
  #7  
Old 10-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Default

Jon,
Can you give me a hint as to which line to move?

Thanks for the reply

Cris
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #8  
Old 10-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Default

Also, I presume that
Code:
if (intValidPassword = 1);
			alert("Your password is valid!")
should be

Code:
if (intValidPassword == 1);
			alert("Your password is valid!")
??

Thanks
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #9  
Old 10-05-2009
Hairy Spider's Avatar
Hairy Spider Hairy Spider is offline
Senior Member
 
Join Date: Mar 2007
Location: Ashford, Kent
Posts: 497
Default

Actually it's 2 lines. I was looking at post 2 when I wrote 1 line.

Moving
Quote:
strPassword = prompt("Please enter a valid password","");
into the while loop will give it a new password to check every loop

Tweaked a little further it will handle the cancel button too:

Quote:
<script language = "JavaScript">

function validatePassword()
{
//Declare and initilise variables
var intIncludesAt = 0; //Changes to 1 if an @ sign is found
var intValidPassword = 0;
var intIncludesAt = 0;
var strPassword = "";
var intFirstChar = 0;
var abort = 0;

while(intValidPassword == 0 && abort == 0)
{
strPassword = prompt("Please enter a valid password","");

if(strPassword != null) // Will be null if cancel button pressed
{
intFirstChar = parseInt(strPassword.charAt(0)); //First character of the password
for (intCount = 0; intCount < strPassword.length; intCount ++)
{
if(strPassword.charAt(intCount) == "@")
{
intIncludesAt = 1;
}
}

if (strPassword.length >= 6 && intIncludesAt == 1 && intFirstChar == 0)
{
intValidPassword = 1;
alert("Your password is valid!")
}
}
else
{
abort = 1;
alert("Password entry aborted")
}
}

}
</script>
(For some reason all the indentation has gone )

And yes to your last question.

Regards,
Jon.
__________________
Faversham Off-Road Cake Club
Cake In... Speed Out!
www.forcc.co.uk

Reply With Quote
  #10  
Old 10-05-2009
c0sie c0sie is offline
*SuPeRsTaR mEmBeR*
 
Join Date: Feb 2006
Location: Cheltenham
Posts: 3,294
Default

*bows at your feet*

Thanks a tonne Jon!
__________________
Previously:
BRCA Micro Section Chairman.
BRCA Micro National Champion.

Currently:
JQ fan.
Bellend.

Forums are better than Facebook groups
Reply With Quote
  #11  
Old 10-05-2009
Hairy Spider's Avatar
Hairy Spider Hairy Spider is offline
Senior Member
 
Join Date: Mar 2007
Location: Ashford, Kent
Posts: 497
Default

Quote:
Originally Posted by c0sie View Post
Thanks a tonne Jon!
No Worries,
Jon.
__________________
Faversham Off-Road Cake Club
Cake In... Speed Out!
www.forcc.co.uk

Reply With Quote
Reply

Thread Tools
Display Modes

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. The time now is 06:36 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
oOple.com