SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry JSP: Form Validation form not working

    I have a form on my website and it has a java script form validator code i got from a free script site. I have gotten 4 of the area's to work but I have put one more on, one called input named "password". Here's my code:

    Java Script
    Code:
      <script language="JavaScript">
    <!--
    
    function SymError()
    {
      return true;
    }
    
    window.onerror = SymError;
    
    var SymRealWinOpen = window.open;
    
    function SymWinOpen(url, name, attributes)
    {
      return (new Object());
    }
    
    window.open = SymWinOpen;
    
    //-->
      </script>
      <script language="JavaScript">
    <!--
    
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("Username", "replyemail", "CurrentProject", "ProjectInfo", "Password");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("You Halo CE Username", "Email Address", "Project Name", "Project Info", "Your Password");
    	// dialog message
    	var alertMsg = "Please complete the following fields:\n";
    	
    	var l_Msg = alertMsg.length;
    	
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    			}
    			if (obj.type == undefined){
    				var blnchecked = false;
    				for (var j = 0; j < obj.length; j++){
    					if (obj[j].checked){
    						blnchecked = true;
    					}
    				}
    				if (!blnchecked){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
    		}
    	}
    
    	if (alertMsg.length == l_Msg){
    		return true;
    	}else{
    		alert(alertMsg);
    		return false;
    	}
    }
    // -->
    And heres the part of my form that has the password input:

    Code:
    <form
     action="http://pub15.bravenet.com/emailfwd/senddata.php" method="post"
     enctype="multipart/form-data" style="margin: 0px;"
     onsubmit="return formCheck(this);">
                  <div style="text-align: center;"> </div>
                  <div
     style="padding: 10px; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-stretch: normal; font-size-adjust: none; text-align: left; color: rgb(142, 167, 96);">
                  <div style="text-align: center;"><big><big><b>Online
    Registration
    Form<br>
                  </b></big></big>
                  <div style="text-align: left;">* = Required</div>
                  </div>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">Your
    Name: (Not required)<br>
                  <input type="text" name="Name" size="34"
     style="width: 230px;"><br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">* Password:<br>
                  <input type="password" name="Password" size="34"
     style="width: 230px;"><br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">* Your Halo CE Username (it will
    also be used on our site): <br>
                  <input type="text" name="Username" size="34"
     style="width: 230px;"><br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">* Current Project/Map Name:<input
     type="text" name="CurrentProject" size="34" style="width: 230px;"><br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">* Project Info:<br>
                  <textarea cols="38" rows="10" name="ProjectInfo"></textarea><br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">Sign
    Up for our monthly newsletter?<br>
                  <input type="checkbox" name="Get newsletter">Yes, Sign me
    up!<br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">* E-mail address: <br>
                  <input type="text" name="replyemail" size="34"
     style="width: 230px;"><br>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;"></div>
                  <div style="text-align: center;">
                  <div style="text-align: justify;"><span
     style="color: rgb(142, 167, 96);">1. By pressing "Accept" below, you
    agree that all the information provided here will be possibly posted
    publicly on our site.<br>
    2. If you leak any of the maps which are not publicly released, your
    account will be deleted and your IP address will be blocked by our form
    so you will not be able to re-sign up. We take the leaking of files
    very seriously and it will not be premitted.<br>
    3. You must agree to these terms by pressing "Accept" or you will not
    be able to join.<br>
                  </span></div>
                  </div>
                  <hr noshade="noshade" color="#8EA760"
     style="width: 100%; height: 5px;">
                  <div align="center"> <input type="submit" name="submit"
     value="Accept"><input type="hidden" name="usernum" size="1"
     style="border: 0px solid black; height: 0px; width: 0px;"
     value="1268962104"><input type="hidden"
     style="border: 0px solid black; height: 0px; width: 0px;"
     name="MAX_FILE_SIZE" value="2000000"><input type="hidden"
     style="border: 0px solid black; height: 0px; width: 0px;" name="cpv"
     value="2"> <input type="reset" name="reset" value=" Clear "></div>
                </form>
                </div>
                </div>
                </td>

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    At a glance, it looks like the JavaScript code you're using isn't set up to handle fields with type="password". Make the addition shown in bold here to add this support:
    Code:
    			case "text":
    			case "textarea":
    			case "password":
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nicely done. Thanks alot!


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
  •