Results 1 to 9 of 9

Thread: calling javascript function from HTML

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Hi,
    I have a ( borrowed ) javascript program ftiens4.js which contains a number of Javascript functions. I want to be able to call a function (clickonnode) inside this javascript file from my image in an HTML file, can someone let me know the syntax. I presume it is associated with the onclick event on my image but need the specifics of the filename.functionName for the JS file.

    I have the following
    <td><img SRC="../regions/maps/map%20uk.jpg" USEMAP="#mapuk" BORDER="0" align="middle" WIDTH="397" HEIGHT="382" onclick="ftiens4.js????????>

    as usual

    thanks in advance.

    Lenin.


  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    If this is a simple include scenario, ignore me.

    Lenin

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    stick this in the <head> section of your page and then just call the function in the usual way.



    Code:
    <SCRIPT LANGUAGE = 'JavaScript'
    SRC="./ftiens4.js">
    </SCRIPT>
    Mark
    -------------------

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Thanks ( again ) Mark. I seem to get an "Object Required" error ( file not located ? in the same directory though so would expect ./XXX to work) when I execute the script from a button click.

    I also found a reference in MSDN requiring a registry setting to be changed in

    HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Inetinfo\parameters\MimeMap

    do you know if this is relevant?



    The function is the .js file is

    function clickOnNode(folderId)
    {
    var clickedFolder = 0
    var state = 0

    clickedFolder = indexOfEntries[folderId]
    state = clickedFolder.isOpen

    clickedFolder.setState(!state) //open<->close
    }


    <head><SCRIPT LANGUAGE = 'JavaScript' SRC="./ftiens4.js"></SCRIPT></head>


    <button class="Button" tabIndex="21" onclick="SetTreeNode();">TTT</button>

    <script LANGUAGE="JavaScript">
    <!--
    function SetTreeNode()
    {
    clickOnNode(9);
    }


    thanks

    Lenin

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    you certainly shouldn't have to change the registry!!!

    you've got some wierd HTML there though.

    for a button I always use <input type=button etc..>

    go back to where you pinched the js file from and have a look at the file in which it is used. You might need a style sheet as well (or somthing like that)


    Mark
    -------------------

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    sorry Mark no luck ( i.e no stylesheets ). I think I will put this aside and revisit, a bit out of my abilities. As usual I didn't mention something which may be critical, that is that the js file is executed in a frameset and my page is in another from, so I would need to call parent.document.scriptName I think.

    Thanks for the pointers, as usual very helpful.

    Lenin.

  7. #7
    Guest
    The path on the SRC to your .js file looks wierd. You have:

    ./ftiens4.js

    If the .js is in the same folder as your project you could just use:

    ftiens4.js

    If it's in your servers virtual root you could use:

    /ftiens4.js

    Why the '.' before the '/'?

    Paul

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Think it means current directory.

  9. #9
    Member
    Join Date
    Sep 2000
    Posts
    49
    Have the .js file in the same directory as your html file and put the follwing between your HEAD tags:
    Code:
    <script language="javascript" src="ftiens4.js"></script>
    Now within your BODY tags try this:
    Code:
    <a href="javascript: clickonnode();">
    <img src="pic.jpg" border="0">
    </a>
    [Edited by N*G*Evangelion on 11-23-2000 at 08:37 AM]

Posting Permissions

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



Click Here to Expand Forum to Full Width