Hello all. I have an issue which I'm trying to tackle but I can't find which way would be best.
I have the following function in a Javascript file:
Code:
function validate(objName, fieldName, objValue, objValue2)
{
var objOut = document.getElementById('msg_' + fieldName);
var params = "";
if(objName == "field_length")
{
params = "?field_length=" + objValue;
}
else if(objName == "postal_code")
{
params = "?postal_code=" + objValue;
}
else if(objName == "phone_number")
{
params = "?phone_number=" + objValue;
}
else if(objName == "email")
{
params = "?email=" + objValue;
}
else if(objName == "afm")
{
params = "?afm=" + objValue;
}
else if(objName == "field_length_no_require")
{
params = "?field_length_no_require=" + objValue;
}
else if(objName == "field_selected")
{
params = "?field_selected=" + objValue;
}
XMLHttp.open('GET', './form_valid.php' + params, true);
XMLHttp.onreadystatechange = function()
{
if(XMLHttp.readyState == 4 && XMLHttp.status == 200)
{
objOut.innerHTML = XMLHttp.responseText;
}
}
XMLHttp.send(null);
}
and then each function in the
php file returns through echo a string which is to be displayed as you can see in innerHtml.
The problem is that I want the Submit button to be disabled only until all fields are valid at which case it will be enabled.
I have thought of returning a variable from
PHP and storing it in Javascript to use it in a big if statement but I can't return any variables from what I've searched.
Maybe I'm going about this whole thing wrong. I'd like to avoid validating in Javascript.
Is there any other way to accomplish this?
Or any ideas in general to get what I want out of this?