0

I am trying to write a code which retrieves values from databases and uses slidetoggle() to slide them on screen.

This is .html file without database retrieval which works perfectly:

<html>
<head>

<script type="text/javascript" src="C:\Users\Mohit\Desktop\jquery-1.9.1.min.js"></script>
</head>
<body onload="handleChange();">

<label><input type='checkbox' onchange='handleChange();'>Check box</label>

<script>
function handleChange()
{
    $('.slideTogglebox').slideToggle();
}
</script>
<div class="slideTogglebox">
    <ul>
        <li><input type="checkbox">Judge1</li>
        <li><input type="checkbox">Judge2</li>
    </ul>
</div>
</body>
</html>

Then I wrote this .jsp file including above jQuery with database retrieval, but in output it is showing only retrieved values, but slidetoggle() function is not working.

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>

<script language="javascript" type="text/javascript" src="C:\Users\Mohit\Desktop\jquery-1.9.1.min.js"></script>
<script language="javascript">
function handleChange()
{

    $('.slideTogglebox').slideToggle();

}
</script>
</head>
<body onload="handleChange();">
<%
    try{
        Connection conn = null;
        ResultSet rs;

            Class.forName("com.mysql.jdbc.Driver");
        conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/aniket","root","");
        String strsql=null;
        strsql="select * from projects";
        Statement stmt=conn.createStatement();
        rs=stmt.executeQuery(strsql);
        while(rs.next())
        {%><br><input type='checkbox' onchange='handleChange();'><%
            out.print("CO"+rs.getInt(1)+"");
            out.print(rs.getString(2));
        }   
       }
        catch(Exception e)
        {
           e.printStackTrace();
           System.out.println(e);
        }
%>
    <div class="slideTogglebox">
    <%
            Connection conn1 = null;
                ResultSet rs1;
            conn1=DriverManager.getConnection("jdbc:mysql://localhost:3306/aniket","root","");
            String strsql1=null;
            strsql1="select * from judges";
            Statement stmt=conn1.createStatement();

            rs1=stmt.executeQuery(strsql1);
            while(rs1.next())
            {%><br><input type='checkbox'><%
            out.print(rs1.getInt(1));
            out.print(rs1.getString(2));
        }%>
</div>
</body>
</html>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user2213232
  • 13
  • 1
  • 3

1 Answers1

3

You should be using a URI scheme url to the jQuery script file, not an absolute filesystem path. Ideally, this would be something like

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

where the jQuery script is part of your app.

If you only ever want to run this on your local machine, you can stick with the filesystem path however it should use the file URI scheme.

<script src="file:///C:/Users/Mohit/Desktop/jquery-1.9.1.min.js"></script>

An even better solution would be to use the Google CDN link, eg

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

One more thing, you should really add a doctype to the top of your document. I recommend HTML5

<!DOCTYPE html>
Phil
  • 157,677
  • 23
  • 242
  • 245