-5

I am very new to jquery and js but have this code in myphp.php file:

<?php
echo "<div><tr><a href='javascript:getspreadsheets();'>Cape Culture (10 years)</a></tr><br />";
echo "<tr><a href='javascript:getspreadsheets();'>Winsters (5 Years)</a></tr><br />";
echo "<tr><a href='javascript:getspreadsheets();'>Kayo (1 year)</a></tr><br />";
echo "<tr><a href='javascript:getspreadsheets(1498);'>Col Timbers</a></tr></div>";
?>

  <script type="text/javascript">
function getspreadsheets(val)
{
    alert(val);
    var self = this,

        activityguid = self.activityguid,
        accountguid  = self.accountguid

        $.fileDownload(
            'data/export.items_to_csv.php',
            {
                httpMethod: 'POST',
                data: {
                    activityguid : activityguid,
                    accountguid  : accountguid,
                    classid      : val
                }
            });
        alert(val);
    //}
}
 </script>

when i run it i get the first alert but then get an error stating the $ is undefined? can some one help please? thanks

charlie_cat
  • 1,790
  • 6
  • 38
  • 72

3 Answers3

1

Make sure that your include for jQuery is before this script section, and that you are actually including jQuery.

bigcakes
  • 216
  • 2
  • 9
0

It sounds like either you are not including jQuery or you're including it after your script. Make sure the jQuery script tag is before your application script.

andy
  • 2,279
  • 1
  • 26
  • 45
  • 2
    since scripts load synchronously, the statement about jQuery not being loaded in time seems to be invalid in the provided context – Zathrus Writer Oct 10 '13 at 12:35
  • Actually it's better to have all of your scripts at the end of your document right before `

    `. Also, jQuery will always load in time because scripts load synchronously. The only way there would be a problem is if the script loads asynchronously because of an `async` attribute in the `` tag. No `async`, no problem.

    – War10ck Oct 10 '13 at 12:43
  • That's very true actually. Bit of a dunce moment on my part haha. – andy Oct 10 '13 at 13:21
  • Edited the original answer – andy Oct 10 '13 at 13:22
0

Add this code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
War10ck
  • 11,732
  • 7
  • 38
  • 50
Nandakumar
  • 949
  • 2
  • 10
  • 27