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