PDA

Click to See Complete Forum and Search --> : calling javascript function from HTML


lenin
Nov 22nd, 2000, 08:27 AM
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.

lenin
Nov 22nd, 2000, 08:30 AM
If this is a simple include scenario, ignore me.

Lenin

Mark Sreeves
Nov 22nd, 2000, 09:53 AM
stick this in the <head> section of your page and then just call the function in the usual way.





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

lenin
Nov 22nd, 2000, 10:16 AM
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

Mark Sreeves
Nov 22nd, 2000, 10:24 AM
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)

lenin
Nov 22nd, 2000, 11:04 AM
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.

Nov 22nd, 2000, 12:18 PM
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

lenin
Nov 23rd, 2000, 02:59 AM
Think it means current directory.

N*G*Evangelion
Nov 23rd, 2000, 04:00 AM
Have the .js file in the same directory as your html file and put the follwing between your HEAD tags:
<script language="javascript" src="ftiens4.js"></script>
Now within your BODY tags try this:
<a href="javascript: clickonnode();">
<img src="pic.jpg" border="0">
</a>

[Edited by N*G*Evangelion on 11-23-2000 at 08:37 AM]