Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hi, Can anyone help... a Javacr

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
hi,

Can anyone help...
a Javacript function that defines a particular area as clickable. Once a particular location within the designated area is clicked, it's X and Y co-ordinate is displayed.
What I am then doing is "posting" these form variables to an action page.

This is OK if I define one clickable area with in 1 form, but I want this option to be avaialble to multiple forms within a page so I enclose the clickable area within 1 form and then define a second clickable area with another form all on one page.
When I then try to click a clickable area I get an error message:

"runtime error, 'document.formname.y' is null or not an object"

My programming experience of Javascript is non-existant.... please help..

I have attached the code below:

-------------------------------------------------------------------------------------------
<html>
<head>
<title>Position your choices</title>
</head>

<body>


<style>
.clickablearea{cursor:hand;}
</style>
</head>

<body>
<script>
function mouseMoved()
{


var eobj,thex,they
eobj = window.event
if(eobj.srcElement.className==&quot;clickablearea&quot;)
{
thex = eobj.clientX
they = eobj.clientY
document.formname.y.value=thex
document.formname.x.value=they
}

}

document.onclick=mouseMoved
</script>

<form name=&quot;formname&quot; ACTION =&quot;previewXYpage.cfm&quot; METHOD=&quot;Post&quot; >
<table bgcolor=&quot;#COCOCO&quot; cellspacing=&quot;1&quot; cellpadding=&quot;1&quot; border=&quot;2&quot;>
<tr>
<td WIDTH=1%><div class=&quot;clickablearea&quot;>This a clickable row</td></div>
</tr>
</table>

The X Co-Ordinate is <input type=&quot;text&quot; name=x><BR>
The Y Co-Ordinate is <input type=&quot;text&quot; name=y>

<INPUT TYPE = &quot;Submit&quot; VALUE =&quot;Enter&quot;>
<INPUT TYPE = &quot;Reset&quot; VALUE =&quot;Clear&quot;>

</FORM>

<form name=&quot;formname&quot; ACTION =&quot;previewXYpage.cfm&quot; METHOD=&quot;Post&quot; >
<table bgcolor=&quot;#COCOCO&quot; cellspacing=&quot;1&quot; cellpadding=&quot;1&quot; border=&quot;2&quot;>
<tr>
<td WIDTH=1%><div class=&quot;clickablearea&quot;>This a clickable row</td></div>
</tr>
</table>

The X Co-Ordinate is <input type=&quot;text&quot; name=x><BR>
The Y Co-Ordinate is <input type=&quot;text&quot; name=y>

<INPUT TYPE = &quot;Submit&quot; VALUE =&quot;Enter&quot;>
<INPUT TYPE = &quot;Reset&quot; VALUE =&quot;Clear&quot;>

</FORM>

</body>
</html>
 
First of all you might want to give x and y an id
eg <input type=&quot;text&quot; name=x id='x'>

this will make them visible in the object model you can then refer to them as window.formname.x.property... and avoid the error you mention here. You do have one or two other problems though.

for example you are declaring your variables in a VB manner like dim x, y, z etc. In Javascript you would both declare and assign them with one statement.

eg var thex=eobj.clientX;

hope this helps,

Nick
 
Hi Nick99,

Thanx for the suggestion.
I trei it but I'm still getting the error.
When you said refer to them window.formname.x.property....what does that mean?

Im completely new to javascript your guidance will be greatly appreciated

Cheers
Sam
 
It means your elements have an id to refer to them by, so you can set it's properties:

-document.all['idName'].property = 'some value' &quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
it depends on which browser (and which version of it) you're targetting
all the above is true and works for ie 4+
it doesn't for ns < 6
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top