By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

two fucntions trigger by onClick

P: n/a
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!="undefin ed" )&&
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>

Feb 16 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Feb 17, 1:18 am, zhengya...@gmail.com wrote:
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.
--
Rob

Feb 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.