1

Every site I've read says a function would just take a parameter if you declare it, however I can't get it to work here.

Working like this:

    <script type='text/javascript'>
    function trackSubmit() { 
        setTimeout(function(){
            ga('send', 'event', 'category', 'action', 'link', 4);
        }, 100);
     }
</script>

And with:

<form onsubmit="trackSubmit()">

However, if I try something like this, it doesn't work.

    <script type='text/javascript'>
    function trackSubmit(category, action, link) { 
        setTimeout(function(){
            ga('send', 'event', category, action, link, 4);
        }, 100);
     }
</script>

<form onsubmit="trackSubmit(testcategory, testaction, testlink)">

What can I do to fix this? Or should I just have multiple functions like trackSubmit1, trackSubmit2, etc? Though that wouldn't be very convenient.

Thank you for any help.

Momololo
  • 17
  • 1
  • 7
  • Please provide some error log, for instance use Chrome with the inspect element tool, from the posted code there may be plenty of possible reasons for such code not working! (e.g. try to pass the parameters also to the function called by the setTimeout, anyhow, setTimeout is generally a poor design choice) – T. Rossi Jun 15 '14 at 15:30
  • Where are those `testcategory, testaction, testlink` variables defined that you use as arguments? – Bergi Jun 15 '14 at 15:31
  • *suggestion :* [**addEventListener**](https://developer.mozilla.org/es/docs/DOM/elemento.addEventListener) – adeneo Jun 15 '14 at 15:40

1 Answers1

1

you need to use qoutation <form onsubmit="trackSubmit('testcategory', 'testaction', 'testlink')"> if there are variable then need to concatenate like \''+testcategory+'\' , ...

Muhammad Ali
  • 1,992
  • 1
  • 13
  • 20