FWIW this has a slightly cleaner main loop in getForm, and most
importantly, the returned offset values are correct for both
Firefox and Konqueror when clicking on the image submit button.
The issue of using enter/return to submit the form seems to
just naturally work with the first submit button becoming the
default "clicked" button.
$.fn.getForm = function() {
var a = [];
var f = this.get(0);
for (i = 0; i < f.childNodes.length; i++) {
var o = f.childNodes[i];
if (o.disabled || o.type == 'reset' || o.name == undefined
|| (o.type == 'checkbox' && !o.checked)
|| (o.type == 'radio' && !o.checked)) continue;
if (o.type == 'image') {
if (f.clicked != o) continue;
if (o.name == 'evaljs') this.doeval = true;
a.push({name: o.name+'_x', value: f.clicked_x});
a.push({name: o.name+'_y', value: f.clicked_y});
} else if (o.type == 'submit') {
if (f.clicked != o) continue;
if (o.name == 'evaljs') this.doeval = true;
a.push({name: o.name, value: o.value});
} else if (o.type == "select-multiple") {
for (j = 0; j < o.childNodes.length; j++) {
var p = o.childNodes[j];
if (p.selected) a.push({name: o.name, value: p.value});
}
} else {
a.push({name: o.name, value: o.value});
}
}
this.farray = a;
return this;
};
$.fn.putForm = function(target, callback) {
var f = this.get(0);
var a = f.action || '';
var m = f.method || 'POST';
if (this.doeval) {
$.xml(m, a, $.param(this.farray), function(r){$.eval(r.responseText);});
} else if (target && target.constructor == Function) {
$.xml(m, a, $.param(this.farray), target);
} else {
$(target).load(a, this.farray, callback);
}
return this;
};
$.fn.form = function(target, callback){
$('input[@type="submit"],input[@type="image"]', this)
.click(function(ev){
this.form.clicked = this;
if (ev.offsetX != undefined) {
this.form.clicked_x = ev.offsetX;
this.form.clicked_y = ev.offsetY;
} else {
this.form.clicked_x = ev.pageX - this.offsetLeft;
this.form.clicked_y = ev.pageY - this.offsetTop;
}
});
this.submit(function(e){
e.preventDefault();
$(this).getForm().putForm(target, callback);
});
return this;
};
--markc
_______________________________________________
jQuery mailing list
discuss@jquery.comhttp://jquery.com/discuss/