473,503 Members | 5,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

two fucntions trigger by onClick

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
1 1726
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2174
by: DS | last post by:
Hi, I can trigger these events successfully if table only has one row: Sub InputField_OnChange() ...... End Sub But, these events cannot be fired if table has more than one row, why? Pls...
6
5172
by: amith | last post by:
hi, i have some 10 radio buttons meant to take the rating from the user. ex: 1 2 3 4 5 6 7 8 9 10 looks O O O O O O O O O O 1 2 3 4 5 6 7 8 9 10 features O O O O O O O O O O
17
61399
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
2
11351
by: kj | last post by:
How does one trigger an event programmatically? I'm interested in how to do this in both the "Level 0" event model as well as in the DOM Level 2 event model. Thanks! kj -- NOTE: In my...
2
3888
by: Sally B. | last post by:
Hi, I have a main page that opens a pop up window when the user clicks a link. The pop up window is a menu and when the user clicks the item, it populates a form input element on the 'parent'...
1
1866
by: ramalingam | last post by:
Hi I am very new to PHP. Please help. I have a HTML code in a php file which takes in USERID and password. I have <input name="Submit" type="button" value="Submit" onClick="funCheck()"/>,...
13
36062
by: Ralph | last post by:
Hi Is it possible to trigger the certain event from JS function? I have an image with on click event handler assigned. Now if like to trigger this event for this image from some other...
4
2411
by: gregincolumbus | last post by:
I am trying to get the financial calculation on this to trigger whenever there is a change to select1. Right now, the user has to click on select2 to trigger the changes. Ideally, a change of...
1
1632
by: Mahesh J K | last post by:
Hi, Pls help me in solving this problem. How to trigger radio button element's eventhandler from the mail body of the mail I am trying like this... strHTMLBody = "<html><head><script...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.