SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
Thread: let's try this again...
-
Sep 10, 2003, 10:39 #1
- Join Date
- Nov 2001
- Location
- Colorado
- Posts
- 2,085
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
let's try this again...
what I'm trying to do is if the username is blank then have it alert them to fill it in and give it focus...[THIS WORKS]
but then, I also want it to check the password and make sure it's not null and if it is have it tell them to fill it out and give IT focus.
Code:<%@LANGUAGE="JAVASCRIPT"%> <% Session("HandHeldObject")= null Session("HandHeldObject")= Server.CreateObject("HandHeldItemMaint.HandHeldATL"); Session.Timeout = 300 //5 hours var objHandHeld = Session("HandHeldObject"); if (Session("HandHeldObject").Open() == false){ %> <script language="JavaScript"> alert("ERROR: " + "<%=objHandHeld.ErrorMessage%>"); </script> <% } //<--FROM ABOVE IF %> <html> <head> <title>Hand Held Logon</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"> function validate() { if( (document.formhandheld.username.value.length <=0) || (document.formhandheld.username.value == "") ) { alert("Enter a usernumber"); document.formhandheld.username.focus(); var authenticate = true; if (authenticate == true) { return false; } else { return true; } } } </script> </head> <body bottommargin="0" topmargin="0" rightmargin="0" leftmargin="0"> <!--code to stop keypad from coming up / DOESNT WORK --> <OBJECT ID="txtNoSIP" CLASSID="clsid:A72D105-40C2-11D6-918E-00C0DF232EEE" width="95" height="20"> <PARAM NAME=VALUE VALUE=""> <PARAM NAME=MAXLENGTH VALUE=30> <PARAM NAME=ALIGNMENT VALUE=LEFT> </OBJECT> <SCRIPT language="JavaScript" FOR="txtNoSIP" EVENT="OnFocus()">txtNoSIP.ShowSIP(false);</SCRIPT> <SCRIPT language="JavaScript" FOR="txtNoSIP" EVENT="OnLostFocus()">txtNoSIP.ShowSIP(false);</SCRIPT> <form name="formhandheld" action="pocketLogInProcess.asp" method="post" onSubmit="return validate()"> <table width="225" height="320" border="0" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#e3e3e3" valign="top"> <table width="100%" height="320" border="0" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="#e3e3e3" height="*" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" align="center" bgcolor="#00CC33"> <font size='-1' face='verdana,arial'><%=objHandHeld.ItemTitle%></font> </td> </tr> <tr> <td> </td><td> </td> </tr> <tr> <td colspan="2"><font face='verdana,arial'>Please Sign On</font></td> </tr> <tr> <td><font face='verdana,arial'>User Number:</font></td> <td align="right"><input name="username" type="text" size="15" maxlength="9"></td> </tr> <tr> <td height="19" ><font face='verdana,arial'>Password:</font></td> <td align="right"><input name="password" type="password" size="15" maxlength="4"></td> </tr> </table> </td> </tr> <tr> <td bgcolor="#999999" height="28"><div align="center"> <input type="submit" name="OK" value=" OK "> <input type="reset" name="Cancel" value=" Cancel "> <input type="button" name="Help" value=" Help " onClick="window.location.href="pocketLogin_Help.asp""> </div></td> </tr> </table></td> </tr> </table></form> </body> </html>
WordPress Plugins: Comment Info Tip
My Blogs: What a Savage | Search-This
Tools: Search Engine Decoder | PageRank Decoder
Podcast: Rand Fishkin | SitePoint Founders
-
Sep 10, 2003, 11:48 #2
- Join Date
- Aug 2003
- Location
- Sussex, UK
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try
Code:<script language="JavaScript"> function validate() { if((document.formhandheld.username.value.length <=0) || (document.formhandheld.username.value == "" )) { alert("Enter a usernumber" ); document.formhandheld.username.focus(); return true; } if((document.formhandheld.password.value.length <=0) || (document.formhandheld.password.value == "" )) { alert("Enter a Password" ); document.formhandheld.password.focus(); return true; } return false; } </script>
-
Sep 10, 2003, 11:51 #3
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ahem
</plug>
Now, for the direct answer
Code:function validate( f ) { if( ( f.username.value.length <= 0 ) || ( f.username.value == "" ) ) { alert( "Enter a usernumber" ); f.username.focus(); return false; } if ( f.password.value.length <= 0 ) || ( f.password.value == "" ) ) { alert( "Enter a password" ); f.username.focus(); return false; } return true; } ... <form name="formhandheld" action="pocketLogInProcess.asp" method="post" onSubmit="return validate(this)">
-
Sep 10, 2003, 11:56 #4
- Join Date
- Aug 2003
- Location
- Sussex, UK
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah, now that comes from focusing too narrowly on the problem at hand and not checking my code and doing it too quickly
I should have looked at what happens on return false or true...
-
Sep 10, 2003, 12:04 #5
- Join Date
- Nov 2001
- Location
- Colorado
- Posts
- 2,085
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok that works, but what is they hit spacebar in both fields, then I get an error
WordPress Plugins: Comment Info Tip
My Blogs: What a Savage | Search-This
Tools: Search Engine Decoder | PageRank Decoder
Podcast: Rand Fishkin | SitePoint Founders
-
Sep 10, 2003, 12:39 #6
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you may have to use a regular expression then. or right a check for spaces, but then you'd have to loop through each character to make sure they didn't hit the spacebar numerous times. look into regular expression, would be more efficient in the long run.
-
Sep 10, 2003, 13:46 #7
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
here's something that may get you started, it won't allow anything in the field except alpha numeric characters. i tested it some, not extensively...
Code:<html> <head> <title>js test</title> <script language="JavaScript"> function validateForm(){ var str=document.forms[0].textfield.value var filter=/[a-zA-Z0-9]/ if (!filter.test(str)){ alert("Those aren't the correct characters!" ); document.forms[0].textfield.focus(); return false; } else{ alert("Those are correct characters!" ); return true; } } </script> </head> <body> <form action="" onSubmit="return validateForm();"> <input type="text" name="textfield"> <input type="submit" name="submit" value="Test the Field"> </form> </body> </html>
-
Sep 10, 2003, 13:52 #8
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
actually, it's not quite right. if you put "1a 433xxx" it still validates. but you can get the drift from this anyway.
-
Sep 10, 2003, 13:58 #9
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
but this pattern seems to work:
Code:function validateForm(){ var str=document.forms[0].textfield.value; //var filter=/^[a-zA-Z0-9]/; var filter=/\W/ if (filter.test(str)){ alert("Those aren't the correct characters!") document.forms[0].textfield.focus(); return false; } else{ alert("Those are correct characters!"); document.forms[0].textfield.focus(); return true; } }
-
Sep 10, 2003, 14:12 #10
- Join Date
- Nov 2001
- Location
- Colorado
- Posts
- 2,085
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I did
Code:isNaN(parseInt(f.username.value))
WordPress Plugins: Comment Info Tip
My Blogs: What a Savage | Search-This
Tools: Search Engine Decoder | PageRank Decoder
Podcast: Rand Fishkin | SitePoint Founders
-
Sep 10, 2003, 14:18 #11
-
Sep 10, 2003, 14:31 #12
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Golgotha
-
Sep 10, 2003, 14:36 #13
- Join Date
- Aug 2003
- Location
- Sussex, UK
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There's an aweful lot of unplugging going on
Bookmarks