-1
$(function()
{
$(".error").hide();
$("#submit").click(function()
{
    //form validate
    var name= $("input#fullname").val();
        if (name == "")
        {
            $("label#name_error").show();
            $("input#fullname").focus();
            return false;
        }
    var email= $("input#email").val();
        if (email == "")
        {
            $("label#email_error").show();
            $("input#email").focus();
            return false;
        }
    var subject= $("input#subject").val();
        if (subject == "")
        {
            $("label#subject_error").show();
            $("input#subject").focus();
            return false;
        }
    var textarea= $("textarea#textarea").val();
        if (textarea == "")
        {
            $("label#textarea_error").show();
            $("textarea#textarea").focus();
            return false;
        }

    var dataString = 'fullname='+name+'&email='+email+'&subject='+subject+'&textarea='+textarea;
    //alert (dataString);return false;
    $.ajax({
        type: "POST",
        url: "form.php",
        data: dataString,
        success: function()
        {
            $("#form").html("<div id='message'></div>");
            $("#message").html("<h2 id='success'>Query Submitted!</h2>").append("<p>You will be contacted shortly...</p><p>Reload the page to submit another query.</p>").hide().fadeIn(1500)
        }
    })
    return false;
});
});

its just a small question

I have this website which has been working perfectly for the past 2-3 months ... but today when I accidentally wandered into the resource section of chrome's console window there was an error saying

"uncaught reference error: $ is not defined"

I haven't found a satisfactory answer on the web anywhere ... your thoughts?

here is the head section... i have not included any scripts anywhere else on the page

<head>

    <meta charset="utf-8">

    <link rel="stylesheet" href="cq.css" type="text/css">

    <script type="text/javascript" src="form.js"></script>

    <link rel="shortcut icon" href="images/favicon.ico" />

    <script src="jquery.js"></script>

    <script src="form.js"></script>

    <!--share-->

    <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>

    <script type="text/javascript">stLight.options({publisher: "ur-c6d56dfc-f929-5bbf-a456-178fc403ae45"});</script>

    <!--share ends here-->



</head>
11
  • 9
    Do you successfully import jQuery ? I'm not sure "has been working perfectly" means the same for you and me... Commented Jan 21, 2013 at 17:29
  • It seems you are missing the jQuery plugin at top of this script. Commented Jan 21, 2013 at 17:31
  • 1
    Is the page working now? Can you share the script inclusion portion of your page? Commented Jan 21, 2013 at 17:31
  • yes jquery is ther in my folder ... i have linked it ... i get the email delivered from yhe form through ajax .. everything is working ... but the console window shows otherwise Commented Jan 21, 2013 at 17:32
  • 1
    It sounds like jQuery hasn't been included by the time this function is called. Right click your webpage when viewing it and view source. Verify jQuery is being included. I have had this problem on ASP.NET projects. I had to include jQuery at the top of the page and include any scripts at the end of the form, because of how the page gets built. Commented Jan 21, 2013 at 17:37

1 Answer 1

2

You're calling your script before referencing jQuery. Change your HTML to:

<script src="jquery.js"></script>
<script type="text/javascript" src="form.js"></script>

You're also importing the same JavaScript file (form.js) twice.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep, I was about to post the same answer. The fact it is imported twice explains both the error in console and why the application is working correctly.
thank you ... :) .. JAI, JAMIE and .. i guess .. LOSTDREAMER :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.