two fucntions trigger by onClick

Z

zhengyan11

Hey,

what I try to do is when a user clicked an image button on my
site, I use onClick to trigger a dialog box and at the same time I use
button.attach("onClick", savecookie) to mark this visitor so that next
time he comes back I can recognize him.If he did not click this image
button on my site, next time I would treat him as a new visitor.

My dialog box works as I expected but it seems that savecookie
function does not do its job since I could not find any cookies
stored. I am using IE7. Anyone has any idea about this? It means that
I cannot trigger two functions from one onclick?


<html>
<head>
<TITLE>THIS IS TEST </TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">

function buttonLoad()
{
var button = document.getElementById("my_button");

if(isTargetPerson())
{

button.attachEvent("onClick", markVisit);

}
else {
button.style.visibility="hidden";
}

}

function isTargetPerson()
{
if (document.documentElement && (typeof
document.documentElement.style.maxHeight!="undefined" )&&
window.XMLHttpRequest && isNewbie() )
return true;
else
return false;
}

function isNewbie()
{
var allcookies = document.cookie;

var pos = allcookies.indexOf("newbie=");
//alert(pos);

if (pos == -1)
return true;

else {
var start = pos + 7;
var end = allcookies.indexOf(";", start);
if(end == -1) end = allcookies.length;
var value = allcookies.substring(start, end);
if (value == "false")
return false;
}

}

function markVisit()
{
var today = new Date();
today.setFullYear(today.getFullYear() + 1);

document.cookie = "newbie=false;expires=" + today.toGMTString();


}


</SCRIPT>
</head>

<BODY>

<div id="search">
<INPUT TYPE="image" id="my_button" src="sp_ie7.gif"
VALUE="somevalue" onClick=somefunction");'>
</div>

<script language="javascript"> window.onLoad=buttonLoad(); </script>

</BODY>

</html>
 
R

RobG

Hey,

what I try to do is when a user clicked an image button on my
site, I use onClick to trigger a dialog box and at the same time I use
button.attach("onClick", savecookie) to mark this visitor so that next
time he comes back I can recognize him.If he did not click this image
button on my site, next time I would treat him as a new visitor.

My dialog box works as I expected but it seems that savecookie
function does not do its job since I could not find any cookies
stored. I am using IE7. Anyone has any idea about this? It means that
I cannot trigger two functions from one onclick?

Yes you can. The easiest way though is to call one function from the
other, then you only need to attach one handler.
<html>
<head>
<TITLE>THIS IS TEST </TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">

The language attribute is deprecated, keep type.

[...]
<BODY>

<div id="search">
<INPUT TYPE="image" id="my_button" src="sp_ie7.gif"
VALUE="somevalue" onClick=somefunction");'>
----------------------------^-----------^

It's always a good idea to start with valid markup. I think you
wanted something like:

... onclick="somefunction();">

</div>

<script language="javascript"> window.onLoad=buttonLoad(); </script>

Javascript is case-sensitive, try:

window.onload = ...


There may be other errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top