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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:33:29+00:00 2026-05-27T18:33:29+00:00

What I am trying to do is the following. I am writing code for

  • 0

What I am trying to do is the following. I am writing code for a sketch using Raphael.js, in an HTML file. To keep the file cleaner, I want to define the long paths in a separate file pathsFile.js, from which I can access the path. Even though I am using Raphael.js, I think my question has more to do with Javascript than with Raphael.js.

The following works:

<!doctype html>  
<html lang="en">

    <head>
        <meta charset="utf-8">          
        <script src="./raphaelJS/raphael.js"></script>
        <script src="./pathsFile.js"></script>
    </head>

    <body>

        <div id="main">

        <div id="figSellerBuyer"></div>
         <script>
            s = 1;
            attrbs = {stroke: "white", "stroke-width": 2};
            pw = 850;
            ph = 450;

            paper = new Raphael('figSellerBuyer', pw*s, ph*s);
                    market = paper.path(paths.marketBoundary);

          </script> 

</body>
</html> 

where file pathsFile.js is:

var paths = {
    marketBoundary: "M 20 20 L 500 20 L 500 430 L 20 430 Z"
}

The problem is:

What I want to do is replace the hard coded numbers in pathsFile.js to depend on variables pw and ph defined in the main HTML file. For example, if I change the pathsFile.js to:

var ph = 450;
var paths = {
    marketBoundary: "M 20 20 L 500 20 L 500 430 L 20 " + ph-20 + " Z"
}

the code still works. But this involves defining ph in the pathsFile.js. Is there a way I can read the values defined in main HTML file.

Thanks for reading this.

  • 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-27T18:33:30+00:00Added an answer on May 27, 2026 at 6:33 pm

    Yes – use multiple <script> blocks:

    <script>
       var s = 1;
       var attrbs = {stroke: "white", "stroke-width": 2};
       var pw = 850;
       var ph = 450;
    </script>
    
    <script src="./pathsFile.js"></script>
    
    <script>
       var paper = new Raphael('figSellerBuyer', pw*s, ph*s);
               market = paper.path(paths.marketBoundary);
     </script>
    

    However, being conscious to global namespace pollution, this could certainly be cleaned up. A simple example of this would be first declaring var myConfig = {}, then assigning all of your variables to myConfig – so that only one top-level variable is being used. (Also, explicitly declare all of your variables with var.)

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

Sidebar

Related Questions

I am looking at better way of writing following code using linq/lambda expression.. I
I keep getting this writing to a closed file error while trying to compile
I'm trying to open multiple pages following a certain format using mechanize. I want
I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
What I'm trying to do this is writing a simple parser for the following
I am trying following, 1. Get response using Ajax from the users selection which
I was trying the following example, but with external URLs: Using WebViews The example
I am trying the following code: <?php $link = mysql_connect('localhost', 'root', 'geheim'); if (!$link)
I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video It works well when runned from the playground
I'm trying the following code to execute a search and it's not working. On

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.