PDA

View Full Version : pls correct my onClick syntax


shibby1011ph
10-16-2002, 08:01 AM
is my syntax correct?

function test(x)
{ x++;
return x;
}

<a href="pagename.jsp" onClick="x=return test(1);">testing</a>

glenngv
10-16-2002, 08:16 AM
<a href="pagename.jsp" onClick="x=test(1);">testing</a>

but where will you need x?

and after the link is clicked, it will go to pagename.jsp

can you explain what it is you actually want to accomplish?

shibby1011ph
10-17-2002, 07:14 AM
oh...never mind the href...x is suppose to count the number of times you clicked the link....pretend its a checkbox and not a link

glenngv
10-17-2002, 07:25 AM
as ive told you, you'd do it like this:

<a href="pagename.jsp" onClick="x=test(1);">testing</a>

of course, you have to declare x as a global variable.

or simply, you can do:

<head>
<script>
var x=0;
</script>
</head>

<a href="pagename.jsp" onClick="x++">testing</a>

and get rid of the function test().
i supposed you're using the value of x somewhere in your code.

glenngv
10-17-2002, 07:31 AM
aha, you're going to used it in your new post http://codingforums.com/showthread.php?threadid=8184

you should have posted that from the very beginning instead of this one.

chrismiceli
10-17-2002, 01:26 PM
i think he wants this

function hi(x) {
++x;
alert(x);
}

<a href="pagename.jsp" onClick="test(1);">testing</a>