user1324106
user1324106

Reputation: 181

I am getting 2 $ in not defined errors

I have a form and 2 javascript functions below but I am getting 2 '$ is defined' errors in my consoles. How can I fix these 2 errors which I have below (the errors are in the line which contains '//err' next to the line:

<body>

<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startImageUpload();' class='imageuploadform' >
<p class='imagef1_upload_process' align='center'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='imagef1_upload_form' align='center'><br/>
<label>Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><label class='imagelbl'>(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/>
<label><input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>
<label><input type='button' name='imageClear' class='imageClear' value='Clear File'/></label>
</p> 
<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>

<script type="text/javascript">
var sourceImageForm; 

function startImageUpload(imageuploadform){
 //err $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
  $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
  sourceImageForm = imageuploadform;

      return true;
}

function stopImageUpload(success){
      var result = '';
      if (success == 1){
         result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
      }
      else {
         result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
      }
     //err  $(sourceImageForm).find('.imagef1_upload_process').css('visibility','hidden');
      $(sourceImageForm).find('.imagef1_upload_form').html(result + '<label>Image File: <input name="fileImage" class="fileImage" type="file"/></label><br/><label>(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/><label><input type="submit" name="submitImageBtn" class="sbtnimage" value="Upload" /></label><label><input type="button" name="imageClear" class="imageClear" value="Clear File"/></label>');
      $(sourceImageForm).find('.imagef1_upload_form').css('visibility','visible');

      return true;   
}

</script>

</body>

Upvotes: 0

Views: 52

Answers (3)

Wandering Digital
Wandering Digital

Reputation: 1868

Include jQuery above your functions. And, make sure they're loaded on page load as follows:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" />
$(document).ready(function () {
    // FUNCTIONS GO HERE
});

Upvotes: 0

Aaron Dufour
Aaron Dufour

Reputation: 17535

The $ variable is most often used by jQuery, which you don't appear to have on your page. This is not part of javascript; its a library. You need to include it with a script tag if you want to use it.

Upvotes: 1

Jordan
Jordan

Reputation: 32552

If you're using jQuery, you need to make sure this code comes after the where you include jQuery, and that it isn't run before document.ready.

Upvotes: 0

Related Questions