SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    runat="server" Golgotha's Avatar
    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>&nbsp;</td><td>&nbsp;</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="&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;">
    	   <input type="reset" name="Cancel" value="&nbsp;&nbsp;Cancel&nbsp;&nbsp;">
    	 <input type="button" name="Help" value="&nbsp;&nbsp;&nbsp;Help&nbsp;&nbsp;&nbsp;" onClick="window.location.href="pocketLogin_Help.asp"">
    			</div></td>
    		</tr>
    	  </table></td>
      </tr>
    </table></form>
    </body>
    </html>

  2. #2
    SitePoint Zealot patrikG's Avatar
    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>

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    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)">
    There are several refactoring steps that could be taken still, but, this should get you going in the right direction.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    SitePoint Zealot patrikG's Avatar
    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...

  5. #5
    runat="server" Golgotha's Avatar
    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

  6. #6
    SitePoint Wizard bbolte's Avatar
    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.

  7. #7
    SitePoint Wizard bbolte's Avatar
    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>

  8. #8
    SitePoint Wizard bbolte's Avatar
    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.

  9. #9
    SitePoint Wizard bbolte's Avatar
    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;
     }
    }

  10. #10
    runat="server" Golgotha's Avatar
    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))
    and it seems to work

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or, you can use fValidate!

    </plug> </again>

    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  12. #12
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Golgotha
    I did
    Code:
    isNaN(parseInt(f.username.value))
    and it seems to work
    ooh, hadn't thought of that. will have to look into that.

  13. #13
    SitePoint Zealot patrikG's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •