Page 1 of 1

minimise this code to make it reusable

Posted: Fri Feb 09, 2007 1:12 pm
by louie35
I have this function that I am using to sumbit a form, but I would like to be able to re-use it without manually duplicating the function and rename it.
Javascript is not my cup-of-tea so the reason i am asking here.

Code: Select all

function doit(){
	var form = document.getElementById('comment_form');
                //those are the fields from form
                // is there a way to do for each....

	ajax.setVar("name",(form.name.value));
	ajax.setVar("email",encodeURI(form.email.value));
	ajax.setVar("url",encodeURI(form.url.value));
	ajax.setVar("comment",encodeURI(form.comment.value));
	ajax.setVar("send_email",encodeURI(form.send_email.value));
	ajax.requestFile = "inc_/comment_check.php";  // page if possible dynamic probably looking into the form action
	ajax.method = "POST";  // method if possible dynamic so i could use doit(method,...)
	ajax.element = "comment_add"; // container dynamic if possible  doit(method,container)
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}