Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Submission via image field

Status
Not open for further replies.
Jan 26, 2001
550
GB
Hello chaps

I am just playing around with my first foray into ajax.
I am attempting to submit a form which can either be submitted via a main submit button, or by a series of image fields which apply to specific rows of the form.
The original server side script would check to see which one of the submit buttons was pressed by checking the value of 'Submit' from the form fields.

Now when the form is submitted using ajax, it seems that the submit field gets passed through with the id of the main submit button, regardless of whether one of the image fields was used to submit it.

The function I am using to extract the values from the form and send them via ajax is as follows:

Code:
function prepareForm(){
	if(!document.getElementById){
		return;	
	}
	if(!document.getElementById("predictionForm")){
		return;
	}
	document.getElementById("predictionForm").onsubmit = function(){
		var data = "";
		for(var i=0; i<this.elements.length; i++){
			data+= this.elements[i].name;
			data+= "=";
			data+= escape(this.elements[i].value);
			data+= "&";
		}
		data += "sender=ajax"
		return !sendData(data);
	};
}

Does anyone have any advice on this situation, as it seems that the "document.getElementById("predictionForm").onsubmit = function()" line is not distinguishing between which method was used to submit the form.

Many thanks

Nick Price

Nick (Webmaster)

 
The easiest way is to set up a hidden form field and give each image an onclick handler to set a value in that hidden form field. That way, when the info is sent to the server you can just check the value in the hidden field to see which button/image was clicked.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top