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

  • SEARCH
  • Home
  • 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 6186457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:53:32+00:00 2026-05-24T01:53:32+00:00

I am creating a page which can play a video file with alternate plug-ins

  • 0

I am creating a page which can play a video file with alternate plug-ins based on users selection. The URL encodes which video should be played.

The page is retrieved from a PHP server script. The user selects the plug-in by clicking on some AJAX links. Each link retrieves from server the required plug-in by doing an AJAX request with a Javascript function. This function must take as a parameter the video ID. On the client side I am using jQuery Javascript framework.

I would like to know which is the best practice for doing this as a design pattern. I am thinking at several alternatives:

  1. use onclick HTML attribute for the AJAX links to call the functions that retrieve content from server
  2. use jQuery $(#element).click() to map the Javascript function which retrieves content.

If I use the first alternative a can easily pass the video ID to the Javascript function:

<a id="X" href="#" onclick="retrieveXPlugin('<?php echo $id ?>')">X Plugin</a>

but the view code is mashed with events code, which is not a good practice.

The second alternative looks better, but I must bind the click event in the same PHP file like this:

<script type="text/javascript">
$(document).ready(function() {
    $('#X').click(function() { 
        retrieveXPlugin('<?php echo $id ?>'); 
    });
}
</script>

As I figure out I cannot include the above code in a separate .js file because I need the server side PHP variable $id. The only way to do this would be to use global Javascript variables which doesn’t look so good.

So, which is the best practice to organize view and events in this example and in any other? I am waiting for your suggestions.

  • 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-05-24T01:53:33+00:00Added an answer on May 24, 2026 at 1:53 am

    You could use, for exemple, the name attribute of your link:

    <a id="X" href="#" name="<?php echo $id ?>">X Plugin</a>
    

    And in a separate .js file:

    $(document).ready(function() {
        $('#X').click(function() { 
            retrieveXPlugin($(this).attr ('name')); 
        });
    }
    

    Or event better, like said in the comment below, is the data-* attribute (thanks Raynos), so you could do that this way:

    <a id="X" href="#" data-xplugin="<?php echo $id ?>">X Plugin</a>
    

    And in a separate .js file:

    $(document).ready(function() {
        $('#X').click(function() { 
            retrieveXPlugin($(this).attr ('data-xplugin')); 
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating page where users can upload/download pdf files which is stored in mysql
I'm creating a mobile website that will include a page from which people can
I am creating one jsp page in which I read in a text file,
I am creating an app where there is a page which enables users to
I am creating a page which dynamically creates input fields using jquery on the
I am creating few pages (including login page) which should only be accessible by
I am creating a login register page which contains two edit text boxes(one for
I am creating a 404.html page in django which will be called when i
I am creating a master page for admin-side of my application, which is using
I am creating Facebook application which get insights for user's page for multiple metric.

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.