www.webdeveloper.com
Results 1 to 8 of 8

Thread: Form Validation help

Threaded View

  1. #1
    Join Date
    Jun 2009
    Posts
    11

    Form Validation help

    Hi I'm trying to create a simple registration form with ajax validation. I've got the form working almost how I'd like... a message appears on the page with the errors for each field entered incorrectly.

    The problem is all the error messages appear in one div together and I would like to have each field have its own div containing only its own error.

    I think I need to wrap my error messages in xml and use something like this -
    Code:
    document.getElementById("feedback1").innerHTML= xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue;
    - but can't seem to get it working

    Does anyone know how I should modify my code to do this?

    Attached are the 3 I'm currently using

    And Here is my code for my ajax page only.
    Code:
    var xmlHttp;
    
    function regForm(thisform) {
    	xmlHttp=GetXmlHttpObject();
    	if (xmlHttp==null) {
     alert ("Browser does not support HTTP Request");
     return;
     }
     var formdata = "";
     formdata = "lname=" + thisform.elements['lname'].value + "&fname=" + thisform.elements['fname'].value + "&email=" + thisform.elements['email'].value + "&username=" + thisform.elements['username'].value + "&pass=" + thisform.elements['pass'].value + "&pass2=" + thisform.elements['pass2'].value;
    	xmlHttp.onreadystatechange=formSubmitted;
    	xmlHttp.open("POST", "adduser.php",true);
    	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    	xmlHttp.setRequestHeader("Content-length", formdata.length);
    	xmlHttp.setRequestHeader("Connection", "close");
    	xmlHttp.send(formdata);
    	return false;
    }
    
    function formSubmitted() {
    	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
    	xmlDoc=xmlHttp.responseXML;
    document.getElementById("feedback").innerHTML = xmlHttp.responseText;
    //document.getElementById("feedback1").innerHTML= xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue;
    	}
    }
    
    function GetXmlHttpObject() {
    xmlHttp=null;
    try
     {
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles