Results 1 to 2 of 2

Thread: Passing JS Variables From HTML to a .JS file

  1. #1
    Join Date
    May 2003
    Location
    Canada
    Posts
    218

    Passing JS Variables From HTML to a .JS file

    How does one do it???

    I want the user to click on a link and, depending on the variable content, the image on the page will change. Basically, how do I pass the variable that I declare in my link to a JS file which then shows the appropriate image?

    Umm... this is the code I have, maybe it'll show you what I'm trying to do:

    Code:
    <a href="#" onClick="javascript: goForth('var projNum=1;');">

    It's obviously wrong, but do you see where I'm going with it? goForth is a function that is defined in my .js file.

    Thanks for any help.
    || t · creative ||

    "The public is more familiar with bad design than good design. It is, in effect, conditioned to prefer bad design, because that is what it lives with. The new becomes threatening, the old reassuring."
    - Paul Rand

  2. #2
    Join Date
    Mar 2004
    Location
    China
    Posts
    3,315
    When passing a variable to a function, you pass the value of the variable, not the definition. For example:

    onClick="javascript: goForth(1);"

    Would send the value 1 to the function such as:

    function goForth(projNum)
    {
    some statements
    }

    In this case the variable projNum would take on the value of 1.

    You can list several variable values and names in the function call. Just separate them by a , comma.

Similar Threads

  1. Passing Flash Variables
    By SlayersOtaku in forum Graphic Design
    Replies: 1
    Last Post: 20 Mar 2010, 04:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •