www.webdeveloper.com
Results 1 to 6 of 6

Thread: two js files from one page

  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Question two js files from one page

    My page at http://frontier.dreamhost.com/askbutt3.htm
    has two buttons, each calling a different .js file. But only one button works at a time...and each button is calling the same file.

    The two .js files are identical except for a different message in each one.

    I am a newbie.

  2. #2
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    Both scripts have a function of the same name, so the second occurence of the function overwrites the first. Simply give the functions different names, and this should work.

    Adam

  3. #3
    Join Date
    Apr 2003
    Posts
    3

    Unhappy

    Thanks, but what would be the "function name" in the aforementioned script (reproduced below)? How would I change it to differ from my second script (identical to the one below except for the src value) ?



    <script language="JavaScript" src="01.js">
    </script>

    <FORM NAME= "msgform1" ACTION="src='01.js'">
    <input type="button" value="Click Here One" onClick="DisplayMsg()">
    </FORM>

  4. #4
    Join Date
    Jan 2003
    Location
    Peg City
    Posts
    638
    It appears as though both js files have this function (I didn't look directly but saw them on your page):

    DisplayMsg()

    Change the name of this function in one of the scripts to

    DisplayMsg2()

    and don't forget to mimic that change in your askbutt3.htm file as well.

    havik

  5. #5
    Join Date
    Apr 2003
    Posts
    3

    Unhappy

    Hmmm...I did that on my page http://frontier.dreamhost.com/askbutt6.htm, changing to DisplayMsg2() on that page and in the second .js file. But the second message still overrides the first, although now the second button doesn't do anything.

  6. #6
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    I had a more detailed look at the two scripts - it seems you have used the same script twice, so all the variable names are the same. You need to either use one copy of the script, passing parameters to the functions so they know which button to change, or rename all the variables in the second script to stop the conflicts.

    Adam

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles