ksmatthews Posted May 19, 2008 Share Posted May 19, 2008 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/106297-ajax-and-form-submission/ Share on other sites More sharing options...
nikefido Posted May 19, 2008 Share Posted May 19, 2008 so you're making ajax calls to validate info like usernames already existing or something like that right? not just if something is a number or something is empty? Link to comment https://forums.phpfreaks.com/topic/106297-ajax-and-form-submission/#findComment-544764 Share on other sites More sharing options...
LemonInflux Posted May 19, 2008 Share Posted May 19, 2008 This should be in the AJAX forum.. Link to comment https://forums.phpfreaks.com/topic/106297-ajax-and-form-submission/#findComment-544765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.