0

i want to add javascript in my html form modal. but i got error "uncaught referenceError: $ is not defined" when i define count variable.

So ,how can i resolve this question.

<div class="modal">
    <form id="multiform">
        <script rel="javascript" type="text/javascript" href="/static/js/jquery.min.js">
            var count=$('select#ip option:selected').length;
            alert(count);
            /*code more*/ 
        </script>
    </form>
</div>

0

2 Answers 2

3

There are 3 mistakes

  • Use src instead of href.
  • Once you have given src to a script tag, then script inside that tag will be ignored.
  • Keep it outside body tag or in head tag.

Demo

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal">
  <form id="multiform">
  </form>
</div>
<script>
  var count = $('select#ip option:selected').length;
  alert(count);
</script>

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

Comments

0

Try this. you are using href insted of src

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="modal">
    <form id="multiform">
        <script  type="text/javascript">
            var count=$('select#ip option:selected').length;
            alert(count);
            /*code more*/ 
        </script>
    </form>
</div>

Comments

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.