Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery function not defined

Tags:

jquery

I have a problem with loading this code. I am sure its something to do with noConflict but i cant seem to get it right.

$(document).ready(
   function spouseName() {
      if ($('#maritalstatus').val() == 'married') {
         $('#spousename').attr("disabled", false);
      } else {
         $('#spousename').val('');
         $('#spousename').attr("disabled", true);
      }
   }
);

by the way, it works on IE but not FF

like image 320
Shakir Avatar asked Jan 10 '12 07:01

Shakir


2 Answers

thanks for the info and answers, it seems this thread helped

Function not defined

firefox does not recognize the function name when it inside the jquery document.ready function. what i did was wrap it inside although it seems unconventional. I just removed the document ready and it works perfectly. seems chrome and FF dont recognize function names within this?

function spouseName() {
  if ($('#maritalstatus').val() == 'married') {
     $('#spousename').attr("disabled", false);
  } 
  else {
     $('#spousename').val('');
     $('#spousename').attr("disabled", true);
  }

}

like image 159
Shakir Avatar answered Oct 11 '22 22:10

Shakir


The "jQuery not defined" error happens if you have not included jQuery or may imported beneath your JavaScript.

It should be like this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">  </script>
<script type="text/javascript" src="myjsfile.js"> </script>

myjsfile.js should be like this:

$(document).ready(function(){
    every function inside this
});
like image 28
Bipin Chandra Tripathi Avatar answered Oct 11 '22 22:10

Bipin Chandra Tripathi