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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:09:07+00:00 2026-05-31T10:09:07+00:00

I have two html files (for add and edit) which contains js codes. These

  • 0

I have two html files (for add and edit) which contains js codes. These two files are identical except few js lines in its functions. Actually I don’t like to have common code for both files. Is there a good way to handle this kind of situations ?

Example:

(file one)

<html>
     <title>title goes here</title>
      <javascript>

            $('#button1').click(function () {
            $.ajax({
                type: "POST",       
                url: '/admin/test/checkcode',
                data: {code:code, id:id}, // in here there is an id
                async: false,                     
                success: function(data){
                }
            });
           }
      </script>  
     <body>

     </body>
</html>

(file two)

<html>
     <title>title goes here</title>
      <javascript>

            $('#button1').click(function () {
            $.ajax({
                type: "POST",       
                url: '/admin/test/checkcode',
                data: {code:code}, // in here there is no id
                async: false,                     
                success: function(data){
                }
            });
           }
      </script>  
     <body>

     </body>
</html>
  • 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-31T10:09:08+00:00Added an answer on May 31, 2026 at 10:09 am

    You may want to try putting that JavaScript code into a separate file. That way, you can just include the single JavaScript file into each of those pages… and only have to make changes to that one JavaScript file.

    For reference, here is a way to include a JavaScript file:

    <script type="text/javascript" src="javascript_file_here.js"></script>
    

    Inside of that JavaScript file, there could be some type of basic function that takes parameters for that data value that is used in the $.ajax() call. For example, something like:

    function example(data1, data2) {
        // your code here
        // then just check for data1 and data2 (etc.)
        // to see what to include in the `data:`
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Afternoon, I am trying have an HTML file containing a frameset which contains two
I have two files: master/newsletter1/file.html master/newsletter2/file.html newsletter1/file.html has a lot of new changes that
I have three files in a folder 'test' one.php two.php print.html And i have
I have two HTML tables which would ideally be placed side by side on
lets say i have two pages links.html & contents.php ... first page contains only
I have two CSS files and I can only edit the 2nd file. My
I have two html pages, when you click on something on the first html,
OK, I have two HTML select elements and a button. I need to disable
I have those two html radio buttons and textarea. I basically want to enable
I have two templates for my HTML email: one for bigger screens, and one

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.