views:

54

answers:

2

I have the following HTML code:

<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<head>
    <title>IT-Services Umfrage - Fragen</title>

    <link rel="stylesheet" type="text/css" href="/IT/umfrage/../../style.css" />
    <link rel="stylesheet" type="text/css" href="/IT/umfrage/css/umfrage.css" />

    <script type="text/javascript" src="/IT/umfrage/../../inc/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="/IT/umfrage/js/umfrage.js"></script>
</head>

<body id="page-show">
    <div class="ueberschriftsbalken"><span>IT-Services Umfrage - Fragen</span></div>
    <br />
    <div id="content">

        <form action="/IT/umfrage/Umfrage/save" method="post" id="umfrageForm">
            <div class="frage radio">
                <p>1. Wie professionell empfinden Sie das Auftreten der IT-Service Anlaufstelle?</p>
                <label for="frage1_1"><input type="radio" name="frage1" id="frage1_1" value="1" /> Lausig</label><br />
                <label for="frage1_2"><input type="radio" name="frage1" id="frage1_2" value="2" /> Schwach</label><br />
                <label for="frage1_3"><input type="radio" name="frage1" id="frage1_3" value="3" /> Durchschnittlich</label><br />
                <label for="frage1_4"><input type="radio" name="frage1" id="frage1_4" value="4" /> Gut</label><br />
                <label for="frage1_5"><input type="radio" name="frage1" id="frage1_5" value="5" /> Hervorragend</label>
            </div>
            <input type="submit" value="Antworten absenden" name="submit" id="submitbutton" />
        </form>
    </div>
</body>
</html>

When clicking on the submitbutton or when pushing the enter key, the form gets submitted. But when i try $('#umfrageForm').submit(), $('form').submit() or anything similar, nothing happens. In Firebug, the function only returns the DOM path to the form element.

What could be the problem that prevents the form from being submitted?

+1  A: 

I think you fire the submit event before the DOM is actually loaded, because if I try it, this code works:

$(document).ready(function(){

    // Submit handler, to prove everything works fine
    $('#umfrageForm').submit(function(){
        alert('hi');
        return false;
    });

    // Fire the submit event
    $('#umfrageForm').submit(); // alerts 'hi'
});

See: jsFiddle

Harmen
itrs more than lily the fact that he is not using the $(document).ready() function. +1
RobertPitt
Nope, I fired the event from the Firebug JS console, so the DOM is ready.
danilo
+1  A: 

You have a field named submit, this clobbers the submit method of the form (with a reference to the DOM node for the field) that jQuery depends on in its own submit method.

Rename it.

David Dorward
Awesome. I already thought it had to be something like that, but didn't find the error... Thanks!
danilo