passing form name & field to function
I'm sort of new to JS, but I have just managed to get a few simple AJAX applications working. Now that I have the basic down, I want to write a generic function since I'm basically doing the same thing over and over. What I'm trying to do is to pass the name of the form and the specific field name to complete the following line: "var testdata = document.form.input.value;".
the complete function looks like this:
If I change the function to include the actual form/field names instead of the variables, then everything works fine. I could, of course, do a series of 'if/else' to test the form name and assign "testdata" the appropriate value, but I would rather try to feed the names through the function to keep it neater and more flexible overall.
function checkInput(filename, form, input)
var queryFile = filename + '.php';
var getInfo = 'checkuser';
var testdata = document.form.input.value;
var cache = + new Date().getTime();
var url = queryFile + '?' + getInfo + '=' + testdata + '&rand=' + cache;
http.open("GET", url, true);
http.onreadystatechange = useHttpResponse;