Momololo
Momololo

Reputation: 17

Javascript Function Parameters Not Working

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.

Upvotes: 1

Views: 3836

Answers (1)

Muhammad Ali
Muhammad Ali

Reputation: 2014

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

Upvotes: 1

Related Questions