Dojo.xhr form submit button value

Posted on June 24th 2011 12:42am Friday, by Blaine

When using the dojo.xhr methods to submit a form, the value of the submit button is not sent with the the other parameters. To solve this all we have to do is get the target that submitted the form and attach it to the content parameter of the xhr method you are using.

var formConnect = dojo.connect(dojo.byId('myForm'), "onsubmit", function(event) {
// Important part
    var content = new Object();
    var target = (event.explicitOriginalTarget)?event.explicitOriginalTarget:null;
    if (target != null && dojo.attr(target, 'name') != null && dojo.attr(target, 'value') != null && (target.tagName == 'BUTTON' || target.tagName == 'SUBMIT')) {
        content[dojo.attr(target, 'name')] = dojo.attr(target, 'value');
    var xhrArgs = {
        form: dojo.byId('myForm'),
// Other important part
        content: content
    var deferred = dojo.xhrPost(xhrArgs);

Leave a Reply