jquery is not working
<p>I am using jquery with ajax. Sometimes, It is giving error <code>$</code> is not defined.</p>

<p>This is my code:</p>

<pre><code>&lt;script language="javascript" type="text/javascript"&gt;
  var base_path="&lt;? echo $this-&gt;baseUrl().'/'; ?&gt;";

    function checkemail()
    {
                var email=document.getElementById('comp_email').value;
                //alert(email);
        if(email!='')
        {

          $.ajax({
                                 url:  base_path + "admin/jobs/emailcheck/",
                                data: "email="+email,
                                type: 'GET',
                         success: function (resp) 
                         {

                                         //alert(resp);

                                        $("#valid_email").html(resp);

                                        //alert($("#valid_email table tr td").text());
                                        if($("#valid_email table tr td").text()=='This firm is not exist in database. Firstly register this firm.')
                                        {
                                                //alert('ok');
                                                $.ajax({
                                                         url:  base_path + "admin/profile/firmadd/",
                                                        data:"flag=jobsController",
                                                        type: 'POST',
                                                 success: function (resp) 
                                                 {
                                                        document.getElementById('firm_add_form').style.display='';
                                                        //alert(resp);
                                                                $("#firm_add_form").html(resp);
                                                                document.getElementById('register_typ').focus();
                                                                return false;
                                                 },
                                                        error: function(e){  alert('Error: '+e);  }  
                                                });                                     
                                        }
                                        else
                                        {
                                                document.getElementById('firm_add_form').style.display='none';
                                                document.getElementById('valid_email').style.display='none';
                                                var comp_name = resp.substring(0,resp.indexOf(',',0));
                                                var comp_web = resp.substring(resp.indexOf(',',0)+1);
                                                document.getElementById('comp_name').value = comp_name;
                                                document.getElementById('comp_web').value = comp_web;
                                                return true;
                                        }
                         },
                                error: function(xhr ,e){ 
                                        alert(xhr.readyState); 
                                        alert('Error: '+e);  }  
                        });
                }
  }
 &lt;/script&gt;
</code></pre>

<p>This function is called on <code>onblur</code> in a textbox and called on <code>onclick</code> on submit button in same form.</p>

<p>But when I call it on <code>onblur</code> it is working properly but when I call it on <code>onclick</code> then it is giving error <code>$ is not defined</code>.</p>

<p>And when I gives alert(email) then it is working properly on <code>onclick</code> on submit button.</p>

<p>my form is below:</p>

<pre><code>        &lt;form id="addfrm" enctype="application/x-www-form-urlencoded" method="post" action=""
  name=""&gt;
    &lt;table align="center" class="tbcss" width="100%" cellspacing="0" cellpadding="0"&gt;
      &lt;tr&gt;
        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="comp_email" class=
        "optional"&gt;Company Email:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;&lt;input type="text" name="comp_email"
        id="comp_email" value="" size="35" onblur="return checkemail()"&gt;&lt;span id=
        "valid_email" align="left" width="55%"&gt;&lt;/span&gt;&lt;/td&gt;

        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="comp_name" class=
        "required"&gt;Company Name:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;&lt;input type="text" name="comp_name"
        id="comp_name" value="" size="35"&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td id="firm_add_form" colspan="4"&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="comp_web" class=
        "optional"&gt;Company Website:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;&lt;input type="text" name="comp_web"
        id="comp_web" value="" size="35"&gt;&lt;/td&gt;

        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="category" class=
        "required"&gt;Job Category:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%"&gt;&lt;select name="category" id="category"&gt;
          &lt;option value="" label="Select Category"&gt;
            Select Category
          &lt;/option&gt;

          &lt;option value="Architecture" label="Architecture"&gt;
            Architecture
          &lt;/option&gt;

          &lt;option value="Manufacturing" label="Manufacturing"&gt;
            Manufacturing
          &lt;/option&gt;

          &lt;option value="IT" label="IT"&gt;
            IT
          &lt;/option&gt;
        &lt;/select&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="job_title" class=
        "optional"&gt;Job Title:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;&lt;input type="text" name="job_title"
        id="job_title" value="" size="35"&gt;&lt;/td&gt;

        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="contact_prsn" class=
        "optional"&gt;Contact Person:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;&lt;input type="text" name=
        "contact_prsn" id="contact_prsn" value="" size="35"&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="right" width="15%"&gt;&lt;label for="close_date" class="optional"&gt;Closing
        Date:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%"&gt;&lt;select name="close_date" id="close_date"&gt;
          &lt;option value="" label="Date"&gt;
            Date
          &lt;/option&gt;

          &lt;option value="1" label="01"&gt;
            01
          &lt;/option&gt;

          &lt;option value="2" label="02"&gt;
            02
          &lt;/option&gt;

          &lt;option value="3" label="03"&gt;
            03
          &lt;/option&gt;

          &lt;option value="4" label="04"&gt;
            04
          &lt;/option&gt;

          &lt;option value="5" label="05"&gt;
            05
          &lt;/option&gt;

          &lt;option value="6" label="06"&gt;
            06
          &lt;/option&gt;

          &lt;option value="7" label="07"&gt;
            07
          &lt;/option&gt;

          &lt;option value="8" label="08"&gt;
            08
          &lt;/option&gt;

          &lt;option value="9" label="09"&gt;
            09
          &lt;/option&gt;

          &lt;option value="10" label="10"&gt;
            10
          &lt;/option&gt;

          &lt;option value="11" label="11"&gt;
            11
          &lt;/option&gt;

          &lt;option value="12" label="12"&gt;
            12
          &lt;/option&gt;

          &lt;option value="13" label="13"&gt;
            13
          &lt;/option&gt;

          &lt;option value="14" label="14"&gt;
            14
          &lt;/option&gt;

          &lt;option value="15" label="15"&gt;
            15
          &lt;/option&gt;

          &lt;option value="16" label="16"&gt;
            16
          &lt;/option&gt;

          &lt;option value="17" label="17"&gt;
            17
          &lt;/option&gt;

          &lt;option value="18" label="18"&gt;
            18
          &lt;/option&gt;

          &lt;option value="19" label="19"&gt;
            19
          &lt;/option&gt;

          &lt;option value="20" label="20"&gt;
            20
          &lt;/option&gt;

          &lt;option value="21" label="21"&gt;
            21
          &lt;/option&gt;

          &lt;option value="22" label="22"&gt;
            22
          &lt;/option&gt;

          &lt;option value="23" label="23"&gt;
            23
          &lt;/option&gt;

          &lt;option value="24" label="24"&gt;
            24
          &lt;/option&gt;

          &lt;option value="25" label="25"&gt;
            25
          &lt;/option&gt;

          &lt;option value="26" label="26"&gt;
            26
          &lt;/option&gt;

          &lt;option value="27" label="27"&gt;
            27
          &lt;/option&gt;

          &lt;option value="28" label="28"&gt;
            28
          &lt;/option&gt;

          &lt;option value="29" label="29"&gt;
            29
          &lt;/option&gt;

          &lt;option value="30" label="30"&gt;
            30
          &lt;/option&gt;

          &lt;option value="31" label="31"&gt;
            31
          &lt;/option&gt;
        &lt;/select&gt; &lt;span class="element"&gt;&lt;select name="close_month" id="close_month"&gt;
          &lt;option value="" label="Month"&gt;
            Month
          &lt;/option&gt;

          &lt;option value="01" label="Jan"&gt;
            Jan
          &lt;/option&gt;

          &lt;option value="02" label="Feb"&gt;
            Feb
          &lt;/option&gt;

          &lt;option value="03" label="Mar"&gt;
            Mar
          &lt;/option&gt;

          &lt;option value="04" label="Apr"&gt;
            Apr
          &lt;/option&gt;

          &lt;option value="05" label="May"&gt;
            May
          &lt;/option&gt;

          &lt;option value="06" label="Jun"&gt;
            Jun
          &lt;/option&gt;

          &lt;option value="07" label="Jul"&gt;
            Jul
          &lt;/option&gt;

          &lt;option value="08" label="Aug"&gt;
            Aug
          &lt;/option&gt;

          &lt;option value="09" label="Spt"&gt;
            Spt
          &lt;/option&gt;

          &lt;option value="10" label="Oct"&gt;
            Oct
          &lt;/option&gt;

          &lt;option value="11" label="Nov"&gt;
            Nov
          &lt;/option&gt;

          &lt;option value="12" label="Dec"&gt;
            Dec
          &lt;/option&gt;
        &lt;/select&gt;&lt;/span&gt; &lt;span class="element"&gt;&lt;select name="close_year" id="close_year"&gt;
          &lt;option value="" label="Year"&gt;
            Year
          &lt;/option&gt;

          &lt;option value="2009" label="2009"&gt;
            2009
          &lt;/option&gt;

          &lt;option value="2010" label="2010"&gt;
            2010
          &lt;/option&gt;

          &lt;option value="2011" label="2011"&gt;
            2011
          &lt;/option&gt;

          &lt;option value="2012" label="2012"&gt;
            2012
          &lt;/option&gt;

          &lt;option value="2013" label="2013"&gt;
            2013
          &lt;/option&gt;

          &lt;option value="2014" label="2014"&gt;
            2014
          &lt;/option&gt;

          &lt;option value="2015" label="2015"&gt;
            2015
          &lt;/option&gt;

          &lt;option value="2016" label="2016"&gt;
            2016
          &lt;/option&gt;

          &lt;option value="2017" label="2017"&gt;
            2017
          &lt;/option&gt;

          &lt;option value="2018" label="2018"&gt;
            2018
          &lt;/option&gt;

          &lt;option value="2019" label="2019"&gt;
            2019
          &lt;/option&gt;

          &lt;option value="2020" label="2020"&gt;
            2020
          &lt;/option&gt;

          &lt;option value="2021" label="2021"&gt;
            2021
          &lt;/option&gt;
        &lt;/select&gt;&lt;/span&gt;&lt;/td&gt;

        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="location" class=
        "required"&gt;Location:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%"&gt;&lt;input type="text" name="location" id="location"
        value="" size="35"&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="job_detail" class=
        "optional"&gt;Job Details:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;
        &lt;textarea name="job_detail" id="job_detail" cols="30" rows="5"&gt;
&lt;/textarea&gt;&lt;/td&gt;

        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="notes" class=
        "required"&gt;Notes:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%"&gt;
        &lt;textarea name="notes" id="notes" cols="30" rows="5"&gt;
&lt;/textarea&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="block" class=
        "optional"&gt;Block:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%"&gt;&lt;input type="hidden" name="block" value=
        "N"&gt;&lt;input type="checkbox" name="block" id="block" value="Y"&gt;&lt;/td&gt;

        &lt;td align="right" valign="top" width="15%"&gt;&lt;label for="source" class=
        "optional"&gt;Job Source/Link:&lt;/label&gt;&lt;/td&gt;

        &lt;td class="element" width="26%" valign="top"&gt;&lt;input type="text" name="source" id=
        "source" value=""&gt;&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="center" colspan="4"&gt;&lt;input type="submit" name="add" id="add" value=
        "Add" onclick="return checkemail();"&gt; &lt;button name="back" id="back" type="button"
        onclick="window.location='/allindiazend/admin/jobs/list'"&gt;Back&lt;/button&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/form&gt;
</code></pre>

<p>can any body help me plz.</p>
