I ran into a rather curious problem today with jQuery (link to the
code at the bottom).


The form:
- I created a simple form with 1 hidden field and 4 buttons:
- 2 <input> buttons of type="submit" and type="button"
- 2 <button></button> buttons, also type="submit" and type="button".
- The 4 buttons have their class attribute set to class="submit"
- The form is submitted to an iframe within the page. Therefore upon
submission, the page should not entirely reload, only the iframe gets
updated.


The jQuery script:
- The script simply grabs all submit buttons and attach certain
actions to their click event. To be more specific: submit the form,
then remove it. Nothing more complicated than that.

$().ready(function(){
    $('.submit').click(function(){
        $form = $(this).parent();
        $form.submit().remove();
    });
});



The desired results:
- Normally, once the user press one of the submit buttons, it is
expected that the form will be submitted (via iframe), a small
confirmation message would appear in the iframe and finally the form
would be removed from the dom.


What actually happens:
- Only 2 of the buttons work as expected: the 2 non submit ones, i.e.
<input type="button"> and <button type="button">
- The 2 submit buttons on the other hand don't submit anything. The
form simply gets removed.


If anyone familiar enough with jQuery can indicate what is going on
here, I would be grateful. I've been using the library for 3 days and
although i think it's an awesome piece of code, there are obviously a
few things that i fell to grasp.


The code:
http://pastebin.com/m32d651ff
If you use php, you can copy and paste it as is in a file under your
webserver and run it. There's only about 3 lines of php, to verify if
the form was submitted and output a message. You can easily convert it
to any other web language.


Any help would be appreciated, but before answering please take the
extra 45 seconds necessary to paste the code under your webserver and
run it. This might save us all a great deal of time usually spent
exchanging to clarify wrong assumptions.

Reply via email to