Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 423683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:12:16+00:00 2026-05-12T19:12:16+00:00

So far during my site development I have been storing all my jQuery functions

  • 0

So far during my site development I have been storing all my jQuery functions in an external .js file, below are two examples of the functions inside:

// Loads the login form into the page.
function loadLoginForm() {
  $('[name=loadLoginForm]').click(function() {
    $("#loadingImage").css({ display:"block" });
    $("#mainWrap").load("modules/web/loginForm.php", null, function(data) {
      loadRegisterForm(this, data);
      validateLoginDetails(this, data);
      characterSelect(this, data);
    });
  });
}

// Loads the register form into the page.
function loadRegisterForm() {
  $('[name=loadRegisterForm]').click(function() {
    $("#loadingImage").css({ display:"block" });
    $("#mainWrap").load("modules/web/registerForm.php", null, function(data) {
      loadLoginForm(this, data);    
      registerUser(this, data);
    });
  });
}

The way I have been triggering these functions was to echo a link onto the page using PHP such as this;

Click <a href="#" name="loadLoginForm"><i>here</i></a> to login.

The problem I am facing now is how do I let the PHP side of the code trigger an event instead of it giving the user a link to trigger it?

The only answer I came up with was to get the PHP to echo some JavaScript so when the page loads the JavaScript will trigger the function needed, but I don’t know how to code this.

A situation where this will need to be used is for example when the user has successfully logged in, I don’t won the PHP to give the user a link to go to the next part I wont it to go there automatically.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:12:16+00:00Added an answer on May 12, 2026 at 7:12 pm

    I think it’s best to have a whole bunch of Javascript functions externally like you seem to be doing. No (or little) code should be executed in that common external JS File. Then in your HTML pages themselves you add some dynamic Javascript:

    <script type="text/javascript">
    $(function() {
      loadLoginForm();
      loadRegisterForm();
    });
    </script>
    

    Alternatively you can put the ready() code inside the functions. This way only the minimal and necessary code gets executed on a page.

    Trust me, I’ve done it the other way (where all the code gets executed on every page) and the page load times get stupidly high very quickly.

    Edit: if you simply want to invoke an event, say you have:

    <a href="#" id="delete">Delete</a>
    

    you just need:

    $(function() {
      $("#delete").click();
    });
    

    (assuming the click handler has been assigned). click() with no arguments triggers a click event.

    You can also effectively set “this” in manually called Javascript. Imagine you have:

    $("#delete").click(delete_stuff);
    
    function delete_stuff() {
      alert($(this).attr("href"));
      return false;
    });
    

    you can call that elsewhere with:

    delete_stuff.call($("#delete")[0]);
    

    That is explicitly setting “this”. See JavaScript call and apply.

    Does that help?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I've been setting up redirects for single pages on my ASP.NET site
So far I have only been updated a view from within its controller. I
So far during my experience in Windows Phone 7 application development I notices there
As far as I understand now() returns the same time during the whole PostgreSQL
I've got as far as telling VC++ to generate ASM files during compilation, which
So far I only found two ways: throw exception play nothing ad.2. Pretty recent
I need to display an image in a resizable dialog (so far all the
I have had many problems in Django (not all of them solved), but this
I have a site that will be down for a few hours while a
I have a site with a bunch of users, and a bunch of nodes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.