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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gurvinder Pal SinghCommented:
So did you checked for the javascript errors?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.