1

i get the error : SyntaxError: Unexpected token ILLEGAL [http://localhost/test/drop:13]

my page code os :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="mini.js"></script>
<script language="javascript">
$(document).ready(function() {
$("#main_div").empty();
$("#drp_name option").each(function() {
  $("#main_div").append("<div>"+ $(this).text() +"</div>")
});
​});
</script>
</head>
<body>
<select name="drp_name" id="drp_name">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
</select>
<div id="main_div"></div>
</body>
</html>

i use jquery v1.7.2

Tarun Baraiya
  • 506
  • 1
  • 9
  • 30

4 Answers4

2

Add the jQuery library to your page.

Put this in the <head>

<head>
<script type="text/javascript"  
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
...
</head>
gdoron
  • 147,333
  • 58
  • 291
  • 367
1

You forgot to add the JqueryScript

you can simply use:

<script src="jquery-1.7.2.min.js"></script>

if you download the jquery script and added to your project

John Smith
  • 1,194
  • 1
  • 12
  • 30
0

you add

<script type="text/javascript" src="mini.js"></script>

but don't include your jQuery library js

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

or if jquery library is in your local

<script type="text/javascript" src="SOURCE_TO_YOUR_LOCAL_FILE"></script>
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
-1

You're not passing anything into the function:

$("#drp_name option").each(function(this) {
  $("#main_div").append("<div>"+ $(this).val() +"</div>")
});

Notice I added 'this' inside the function after .each(...

I also changed $(this).text() to $(this).val() as you're pulling a value from the option element.

Fluidbyte
  • 5,162
  • 9
  • 47
  • 76