2

Below is the jsp code.

<head>
    <link rel="stylesheet" type="text/css" href="<%=contextPath %>/style_sheet/page_header.css" >
    <link href="<%=contextPath %>/scripts/jQuery/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script  src="<%=contextPath %>/scripts/jQuery/jquery.min.js" ></script>
    <script  src="<%=contextPath %>/scripts/jQuery/jquery-ui.min.js"></script>
    <script src="jscript.js" ></script>

    <style>
        .pageWidth
        {
            width: 800px;
        }
    </style>

    <script>
        $(document).ready(function(){
            $("#startDatePicker").datepicker();
        });
    </script>

    <title>GFW Voice OUT Files Trend</title>


</head>
<body>

      <table width="800x" border="0" align="center">
         <tr>
            <td>Start Date: <input type="text" id="startDatePicker" /></td>
         </tr>
      </table>

</body> 

I get an error at the syntax

$(document).ready(function(){
   $("#startDatePicker").datepicker();
});

Error

The function $(HTMLDocument) is undefined.

I though eclipse is getting confused between EL and jQuery syntax, but using \$ did not help. what am I doing wrong? All I want to do is use jQuery datepicker.

Sully
  • 14,672
  • 5
  • 54
  • 79

3 Answers3

1

jquery file is not installed correctly. Use that code its work.

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <script>
$(function() {
    $( "#datepicker" ).datepicker();
});
</script>
 <title>Test</title>
</head>
<body>

Date: <input type="text" id="datepicker" />
</body>
  </html>
saitakyuz
  • 76
  • 4
0

Use noConflict to resolve the conflict.

Vaishak Suresh
  • 5,735
  • 10
  • 41
  • 66
0

try some of these:

<table width="800x" border="0" align="center">
           //----^-----------------remove the x here no need of it

and

jQuery(document).ready(function($){
   $("#startDatePicker").datepicker();
});
Jai
  • 74,255
  • 12
  • 74
  • 103
  • Thanks. that x was a typo. Tried this - jQuery(document).ready(function($){ $("#startDatePicker").datepicker(); }); But I get this error on the word jQuery - The function jQuery(HTMLDocument) is undefined –  Dec 04 '12 at 18:25
  • Sorry, that shouldn't be there. Since I thought the $ sign in a jsp is causing issues I tried including the script above in a separate file. But that didn't work either. –  Dec 04 '12 at 18:28
  • your code is working fine: http://jsfiddle.net/cQqDu/ just make sure you are refering your jquery plugin file well. – Jai Dec 04 '12 at 18:31
  • It works fine as an HTML page. But the moment I include it in JSP it stops working. –  Dec 04 '12 at 18:33
  • src="<%=contextPath %>/scripts/jQuery/jquery.min.js" your jsp page gets it when page loads. – Jai Dec 04 '12 at 18:36
  • have you tried with cdn hosted src paths like: – Jai Dec 04 '12 at 18:38
  • Yes! that worked. Thanks for your help Jai. You are a good man. –  Dec 04 '12 at 18:43