1 Replies - 7491 Views - Last Post: 03 May 2009 - 07:00 AM

#1 poluris82  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-May 09

JQuery/Javascript not working in jsp file

Post icon  Posted 02 May 2009 - 09:54 AM

I'm a jquery newbie and am trying to use it in a simple web application. This application has a controller servlet that forwards the request to a 'login.jsp' page by default. In the login.jsp page, I used Jquery for the hover effect on the submit button.
If I name my file 'login.html', it works absolutely fine. If I rename it to 'login.jsp', the javascript is not working. I see the following error in Firebug console:

Quote

syntax error
[Break on this error] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n"

My login.jsp file:
<!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=iso-8859-1">
   <title>
	  Login Page
   </title>
   <link rel=stylesheet href="../css/qtool.css" type="text/css" media=screen>
   <script type="text/javascript" src="jquery-1.3.2.min.js" ></script>
   <script type="text/javascript" src="login.js" ></script>
</head>
<body>
   <div id="container">
	  <div id="box" class="loginBox">
		 <form method='POST'>
			<input type="text" name="user" id="user" size=10/>
			<br />
			<input type="password" name="pwd" id="pwd" size=10/>
			<br />
			<input type="image" name="submit" id="submit" />
			<input type="hidden" name="action" value="login"/>
		 </form>
	  </div>
   </div>
</body>
</html>



My login.js file:
$(function() {
   //Load the default button
   $('input#submit').attr('src', '../images/new/loginButton.png');
   
   //When mouse hovers on button, show button_hover.png, else show button.png
   $('input#submit').hover(function() {
	  $(this).attr('src', '../images/new/loginButton_hover.png');
   }, function() {
	  $(this).attr('src', '../images/new/loginButton.png');
   });
   
   //Set the max length of the user ID text box
   $('input#user').attr('maxlength', '8');
   
   //Set the max length of the password box
   $('input#pwd').attr('maxlength', '8');
   
   $('input#submit').click(function() {
	  return validateInput();
   });
   
   
   function validateInput() {
	  if (($('#user').val() == null) || ($('#user').val() == '')) {
		 $('#warning').remove();
		 $('<img src="../images/warning.png" alt="warning" id="warning"/>').insertAfter('#user');
		 $('input#user').focus();
		 return false;
	  };
	  
	  if (($('#pwd').val() == null) || ($('#pwd').val() == '')) {
		 $('#warning').remove();
		 $('<img src="../images/warning.png" alt="warning" id="warning"/>').insertAfter('#pwd');
		 $('input#pwd').focus();
		 return false;
	  };
   };
});


I have the files 'login.jsp', 'login.js', 'jquery-1.3.2.min.js' under the webapps/QT/jsp/ folder. I think this might be a small problem, but am unable to fix it. Hope someone can help.

Thanks,
poluris82

Is This A Good Question/Topic? 0
  • +

Replies To: JQuery/Javascript not working in jsp file

#2 sethp212  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-May 09

Re: JQuery/Javascript not working in jsp file

Posted 03 May 2009 - 07:00 AM

I would suggest using <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

instead of the html 4.01 doctype.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1