Jump to content

form validation


ksmatthews

Recommended Posts

HI All,

 

I would like to ask a question about ajax and form validation

 

I am using some ajax code as follows ...

 

function showHint(str)

{

xmlHttp = GetXmlHttpObject();

 

if (xmlHttp == null)

  {

  alert ("Browser does not support Ajax HTTP Requests");

  return;

  }

 

// get ID of destination object

results = validation_fields.split("|");

destination_id = results[2];

 

if(str.length==0)

  {

    document.getElementById(destination_id).innerHTML="";

    return;

  }

 

// assemble URL string

var url = "../global_php/ajax_validation.php";

url = url + "?value=" + str.value + validation_fields;

url = url + "&sid=" + Math.random();

 

// The onreadystatechange property stores the function that will process the response from the server

// Each time the readyState changes, the onreadystatechange function will be executed.

xmlHttp.onreadystatechange = stateChanged;

xmlHttp.open("GET", url, true);

xmlHttp.send(null);

}

 

 

// FUNCTION: Checks server state and returns data to calling form

// PARAMETERS: NONE

// RETURNS: void (populates form object with returned data)

function stateChanged()

{

// The readyState property holds the status of the server's response

if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")

  {

    // capture result

var response = xmlHttp.responseText;

 

    // The data sent back from the server is assigned to submitted destination

    document.getElementById(destination_id).innerHTML = response;

  }

}

 

OK. The xmlHttp.responseText will show on the form whatever my php script echoes - in this case error

messages for incorrect input.

 

I need to be able to process those ajax generated messages client side in order to prevent  my form from

being submitted. At the moment the messages are displaying OK but the user can choose to ignore them

and submit erroneous data anyway.

 

How can ajax and javascriipt be used to actually enforce client side validation ?

I have thought about disabling the submit button but how ??

 

regards,

 

Steven M

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.