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 8018125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:03:22+00:00 2026-06-04T21:03:22+00:00

I understand that you can put your $(document).ready() code into separate files from the

  • 0

I understand that you can put your $(document).ready() code into separate files from the html, however as part of my javascript I use some calls back to codeigniter PHP functions such as site_url() which doesn’t work when part of a separate .js file.

Here’s an example:

login_page.php

<script type="text/javascript" src="<?php echo site_url('scripts') . '/' . 'app/login_page.js'; ?>"></script> 
<div id="loginForm" class="prepend-2 column span-21">
    <p class="tips"></p>
    <div class="column span-10">
        <dl>                
            <dt><label>Email:</label></dt>
            <dd><input type="text" name="email" id="email" class="text" /></dd>
        </dl>
    </div>
    <div class="column span-10 last">
        <dl>                
            <dt><label>Password:</label></dt>
            <dd><input type="password" name="password" id="password" class="text" /></dd>
        </dl>
    </div>
    <div class="column prepend-7 span-10 append-5 ">
        <dl>                
            <dt><label>&nbsp</label></dt>
            <dd><input type="submit" value="Login" id="loginButton" /></dd>
        </dl>
    </div>
</div>

login_page.js

$(document).ready( 
function()
{
    //login
    $("#password").keyup(function(event){ if(event.keyCode == 13){          $("#loginButton").click();}}); //submit on enter key
    $('#loginButton').click(function()
    {            
        do_login($("#email"), $("#password"), $(".tips"), "<?php echo site_url('dashboard'); ?>", "<?php echo site_url('login/log_in'); ?>");
        return false;
    });
});

So the problem here is in the do_login I’m trying to call PHP site_url but it obviously won’t work. It all works ok if I have the javascript in my php inline but that makes the files rather large and I’d prefer separate file.

What I need to know is this even possible? If so, has anyone come up with an elegant solution to this problem?

  • 1 1 Answer
  • 0 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-06-04T21:03:24+00:00Added an answer on June 4, 2026 at 9:03 pm

    You can define the base_url as a JS global variable or even better declare a JS global object with all url’s you may need later in your login_page.php before including login_page.js. Then they will be in a separate container and will be available in any JS code loaded after that declaration, Inline or external.

    <script type="text/javascript">  
        window.URLS  = {
          "BASE_URL" : "<?php echo site_url(....); ?>",
          "LOGIN_URL" : "<?php echo site_url(....); ?>",
          "DASHBOARD_URL" : "<?php echo site_url(....); ?>",
        };
    </script>
    

    Then use it in login_page.js like

    do_login($("#email"), 
             $("#password"), 
              $(".tips"), 
              URLS.DASHBOARD_URL, 
              URLS.LOGIN_URL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that you can use the initiate parameter for a Form class from
I understand that I can use the cache=TRUE option to cache an R code
I understand that Git can be used without a central repository. However, I am
I understand that this can be done at release using the maven-gpg-plugin. However, I
I understand that spring can manage your sessions for you, if configured like so:
I've noticed that $(document).ready(..) causes a noticable delay in applying javascript effects. However I
I understand that I can call ToString().IndexOf(...), but I don't want to create an
I understand that I can change a sql table using the follow sp: EXEC
So I understand that you can check a password in Spring Security with salt
I'm reading up about attributes and understand that they can be made to apply

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.