hijax form submit + detect which submit button was pressed


document.observe("dom:loaded", function() {
  var form = document.forms[0],
      button = null

  function isSubmitButton(element) {
    var name = element.nodeName.toLowerCase()
    return (
      (name == 'input' && element.type == 'submit' || element.type == 'image') ||
      (name == 'button' && element.type == 'submit')
    ) && element.name
  }

  form.observe('click', function(e) {
    var element = e.element()
    if (isSubmitButton(element)) {
      button = {}
      button[element.name] = element.value || true
    }
  }).observe('submit', function(e) {
    this.request({ parameters: button })
    e.stop()
  })
})