Jump to content

ajax and form submission


ksmatthews

Recommended Posts

HI All,

 

I understand how ajax can be used to enhance the user experience in providing clues about invalid

user input into forms.

 

What I would like to know is whether or not there is a way of using ajax to actually PREVENT a form

being submitted unless all fields have been correctly completed. It is certainly possible to disable

the submit button when a field has been incorrectly filled in, but how could you do this for multiple

fields ?

 

Here are some code snipptes ...

 

..........

..........

// 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 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;

 

// set submit button

if(response.indexOf("Error") == -1)

  document.getElementById("submit").disabled = false;

else

  document.getElementById("submit").disabled = true;

  }

}

 

regards,

 

Steven M

Link to comment
https://forums.phpfreaks.com/topic/106298-ajax-and-form-submission/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.