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() {

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.
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.

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
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
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??
<!--#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)
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
  End If
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">
<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" />
<script language="javascript" type="text/javascript" src="../JScript/admin.js"></script>
<script language="javascript" type="text/javascript" src="../JScript/jquery.js"></script>

<form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>">
  <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 align="center">Username
    <input name="frmuser" type="text" id="frmuser" value="" />
  <p align="center">

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

Set Rsuser = Nothing

Open in new window

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.
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.
Gurvinder Pal SinghCommented:
So did you checked for the javascript errors?
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.