jquery doesn't work inside a function - only outside?

This is a crazy one. I have been using Jquery fine on building my site. I have an admin section in another folder.

Jquery is not working if it is inside a function. I've tested with this:
 
$(document).ready(function() {
alert("morning");
 });

If I put the alert above the function - the alert comes up. Inside the function it doesn't.

I've checked the paths to jquery.js and it's fine. These admin pages are p/word protected using asp vb but that shouldn't affect JavaScript should it? After all the alert works outside the function.

Thanks for your help.
swordfishsoupAsked:
Who is Participating?
 
swordfishsoupAuthor Commented:
Ok< got it

The links to the scripts have to be in the right order - crazy though in the main folder it wasn't a problem.
Thanks for your help anyway>

It's here if anyone else comes up against this.
http://stackoverflow.com/questions/339314/jquery-is-undefined/1357559#1357559

D
0
 
Gurvinder Pal SinghCommented:
two possible reasons,
1) your document is not ready because of some javascript error or some infinite loop
2) you jquery path is not correct.

Please check for the same
0
 
Shinesh PremrajanEngineering ManagerCommented:
Execute the script in firefox and press control+shift+J it will show the possible errors in the page
Hope this helps
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
swordfishsoupAuthor Commented:
Hi gurvinder.

I don't think so - it's very odd. I have put an alert at the top of the jquery page to make absolutely sure that the path is correct. It is.

There isn't any other Javascript on that page that could make a loop (see below). The alert works out of the function but not inside??
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/discburnerdata.asp" -->
<%
Dim Rsuser
Dim Rsuser_cmd
Dim Rsuser_numRows

Set Rsuser_cmd = Server.CreateObject ("ADODB.Command")
Rsuser_cmd.ActiveConnection = MM_discburnerdata_STRING
Rsuser_cmd.CommandText = "SELECT Username, Password FROM tblUsers" 
Rsuser_cmd.Prepared = true

Set Rsuser = Rsuser_cmd.Execute
Rsuser_numRows = 0
%>
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("frmuser"))
If MM_valUsername <> "" Then
  Dim MM_fldUserAuthorization
  Dim MM_redirectLoginSuccess
  Dim MM_redirectLoginFailed
  Dim MM_loginSQL
  Dim MM_rsUser
  Dim MM_rsUser_cmd
  
  MM_fldUserAuthorization = ""
  MM_redirectLoginSuccess = "control.asp"
  MM_redirectLoginFailed = "http://www.discburner.co.uk"

  MM_loginSQL = "SELECT Username, Password"
  If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
  MM_loginSQL = MM_loginSQL & " FROM tblUsers WHERE Username = ? AND Password = ?"
  Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
  MM_rsUser_cmd.ActiveConnection = MM_discburnerdata_STRING
  MM_rsUser_cmd.CommandText = MM_loginSQL
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 50, MM_valUsername) ' adVarChar
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 50, Request.Form("frmpword")) ' adVarChar
  MM_rsUser_cmd.Prepared = true
  Set MM_rsUser = MM_rsUser_cmd.Execute

  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%>
<!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=iso-8859-1" />
<title>log in</title>
<link href="../dbadmin.css" rel="stylesheet" type="text/css" />
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<script language="javascript" type="text/javascript" src="../JScript/admin.js"></script>
<script language="javascript" type="text/javascript" src="../JScript/jquery.js"></script>
</head>
<body>

<form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>">
  <label>
  <div align="center" class="admincellheader" id="testquery"><br />
    <img src="../img/cd-duplication-prices.jpg" name="pic" width="223" height="244" id="pic" />Admin Login <br />
  </div>
  <p>&nbsp;</p>
  <div align="center">Username
    <input name="frmuser" type="text" id="frmuser" value="" />
  </div>
  </label>
  <p align="center">
    <label>

Password
    <input name="frmpword" type="password" id="frmpword" value="" />
    </label>
  </p>
  <p align="center">&nbsp;</p>
  <p align="center">
    <label>
    <input type="submit" name="Submit" value="Submit" id="button" />
    </label>
  </p>
</form>
<div>



</div>
</body>
</html>
<%
Rsuser.Close()
Set Rsuser = Nothing
%>

Open in new window

0
 
swordfishsoupAuthor Commented:
That's interesting shinug.
Good tip - the error was that the $ in the code below was undefined?


// JavaScript Document
 $(document).ready(function() {
  alert("morning");// put all your jQuery goodness in here.
 });
0
 
swordfishsoupAuthor Commented:
I just double checked and put an alert at the top of the jquery.js page. commented out the other one and it alerts so the jquery file is there.
0
 
Gurvinder Pal SinghCommented:
So did you checked for the javascript errors?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.