FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


javascript problem





riyadh
Code:

var minpwlength = 6;
var maxpwlegnth = 30;

var STRENGTH_SHORT = 0;
var STRENGTH_WEAK = 1;
var STRENGTH_FAIR = 2;
var STRENGTH_STRONG = 3;

img0 = new Image();
img1 = new Image();
img2 = new Image();
img3 = new Image();

img0.src = 'pw_too_short.png';
img1.src = 'pw_fair.png';
img2.src = 'pw_medium.png';
img3.src = 'pw_strong.png';

var strengthlevel = 0;

var strengthimages = Array(img0.src,
      img1.src,
      img2.src,
      img3.sr);

function updatestrength(pw) {

   if( istoosmall(pw)){
      strengthlevel = STRENGTH_SHORT;
   }
   else if( !isfair(pw)){
      strengthlevel = STRENGTH_WEAK;
   }
   else if( hasnum(pw)){
      strengthlevel = STRENGTH_STRONG;
   }
   else {
      strengthlevel = STRENGTH_FAIR;
   }

   document.getElementById('strength').src = strengthimages[ strengthlevel ];
}

function isfair(pw){
   
   if(pw.length < fairpwlength){
      return false;
   }
   else {
      return true;
   }
}

function istoosmall(pw){

   if(pw.length < minpwlength){
      return true;
   }
   else {
      return false;
   }
}

function hasnum(pw){
   
   var hasnum = false;

   for(var counter = 0; counter < pw.length; counter ++){
      if(!isNaN(pw.charAt(counter))){
         hasnum = true;
      }

   }



   return hasnum;


}


this script was meant to show how strong a user's password is when they choose one for the forum in my site. depending on the number of characters, it displayed a picture. but the problem is tht there is an error when i input something into the password field. it says tht the function i'm calling is undefined.

the code for the html page is below:

Code:

<body onload="document.getElementById( 'password' ).focus();">
<div>Enter your password here:</div>
<br />
<div>
    <input maxlength="15" onkeyup="updatestrength( this.value );" type="password" name="password" id="password" value="" />
    <img src="images/tooshort.jpg" id="strength" alt="" />
</div>
</body>
Straevaras
You've got some typos in your code. The logic behind it works just fine, but here's where the typos are.

You forgot to declare fairpwlength here:
riyadh wrote:
Code:
var minpwlength = 6;
var maxpwlegnth = 30;

And it's being called here:
riyadh wrote:
Code:
function isfair(pw){
   
   if(pw.length < fairpwlength){
      return false;
   }
   else {
      return true;
   }
}

And plus you have a typo here.
riyadh wrote:
Code:
var strengthimages = Array(img0.src,
      img1.src,
      img2.src,
      img3.sr);

The last line should be "img3.src);".

Any other problems let me know. And by the way, if you use Firefox I recommend getting the firebug extension, it's very useful in debugging your JavaScript. That and the Venkman JavaScript Debugger.
TheMasterCheaif
Can you use javascript on your desktop??

(i know i have alot of quetions)
Straevaras
You can use JavaScript as long as you have a JavaScript enabled browser. Unlike PHP, you can test JavaScript in your My Documents, on your Desktop, or on your webserver. It doesn't matter where the file is. It all depends on your browser. As long as you have your browser up to date (at least within the last 3 or 4 years) JavaScript should work for you. But be careful, if you develop an in-depth script, you should test it on multiple browsers to make sure it works properly.

*EDIT* Disclaimer: You can test PHP on your home computer but it requires additional software to do that.
TheMasterCheaif
Thanks agin(i got to go learn javascript)
Related topics
Menu problem
Navigation Script (javascript) Help Please!
JavaScript confirm() problem
PHP Question
math problem with javascript
Javascript problem...I think :S
JavaScript problem in IE7
Help with php and java script
JavaScript Problem
embedding javascript menu simple problem
Beginner CSS/Javascript problem.
help needed with css & javascript
Tricky Javascript Problem
AdBlock Plus on OS X Javascript Problem
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.