Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'$' is undefined javascript error

Tags:

jquery

asp.net

<script type="text/javascript">
    $(function() {
        $('#WaterMark').draggable(
                    {
                        start: function(e, ui) {
                        },
                        cursor: 'move',
                        zIndex: 2700,
                        revert: 'invalid',
                        containment: '#OriginalImageContainer'
                    });
        $('#OriginalImage').droppable({
            hoverClass: 'DroppableOver',
            drop: InitializeWaterMark
        })
    });

    var InitializeWaterMark = function() {
        var position = $('#WaterMark').position();
        var imgPosition = $('#OriginalImageContainer').position();
        document.getElementById('xpos').value = position.left - imgPosition.left;
        document.getElementById('ypos').value = position.top - imgPosition.top;

    }
    </script>

this is a sample javascript code i got regarding drag and drop of images in a asp.net webpage...But it returns a error stating '$' is undefined..please help me out

like image 940
Karthik Avatar asked Apr 22 '26 03:04

Karthik


1 Answers

At a guess, I'd say you were missing the library to support that script (probably jQuery).

You need to include a reference to the JavaScript framework in order to get the draggable functionality you're looking for.

Try adding the following to your page (before the script block in your example):

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>
like image 84
Phil.Wheeler Avatar answered Apr 24 '26 21:04

Phil.Wheeler