0

I am trying to run this in Chrome/Firefox Console but not having any luck.

(function(d) {
  var form = d.getElementsByTagName('form');
  var i = form.length;

  while (i--) {

    form[i].addEventListener("submit", function(evt){
        evt.preventDefault();
    }, false);

    xhr = new XMLHttpRequest();
    xhr.open("POST", "http://example.com/", true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send("media_id=" + form[i].elements["media_id"].value);

  }
})(this.document);

Can anyone spot any problems with it? Thanks

EDIT: I have fixed the problem. Thanks @Niklas

4
  • I see you adding an event listener, but you aren't submitting the form here. Commented Jun 17, 2011 at 23:51
  • jquery ajax in browser console? Commented Jun 17, 2011 at 23:55
  • Two important questions: 1. What do you expect this script to do? 2. What is actually happening? Commented Jun 18, 2011 at 0:05
  • 1. As the subject states "Submitting multiple forms with Javascript (no refresh)" - I want it to submit all the forms on the page. 2. Nothing. I am writing something now to hit the submit buttons. Not sure if it will work. Commented Jun 18, 2011 at 0:09

1 Answer 1

1

The problem is that you are preventing the form submissions but not actually doing anything to send them. You'd presumably want to add some ajax to send the data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.