0

so I have a form wuth a button. On click i need to use to run some google analytics code (_gap.push). This wasnt working so I have decided to do an alert to do some test. The alert showing the word "outside" works however the alert showing the word "inside" is not working. So that means that it is not going into that function

Js code

    applyRegisterNewUserListener: function() {
        alert ("outside")
        // Form that attempts to register users
        $(document).on('submit', 'form#signup-form', function() {
            alert ("inside"
            _gaq.push(['_trackEvent', 'register', 'account', 'form',, false]);
        })
    },

html

<form method="post" id="#signup-form">
<input type="submit" value="submit">
</form>

I really cannot understand what is the problem. The function is being called too.

Rene Zammit
  • 1,041
  • 5
  • 17
  • 40
  • 2
    Your JS-Code is broken. Please read http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html too. – Grim Aug 07 '13 at 09:48

1 Answers1

2

The # sign should not be in the id for the form markup.

<form method="post" id="signup-form">

There is also a syntax error in this section of the code.

$(document).on('submit', '#signup-form', function(event) {
    event.preventDefault(); //do not submit form
    alert ("inside"); // alert is missing );
    _gaq.push(['_trackEvent', 'register', 'account', 
                     'form',"", false]); //replace undefined param
});   //add ;

I'm not sure this code needs to be in listener function. It could simply be included as a regular script since it will not execute until the submit event is fired.

Kevin Bowersox
  • 88,138
  • 17
  • 142
  • 176