...

View Full Version : Multiple Functions on a button



DR.Wong
03-08-2005, 11:33 AM
Hey Guys, how do I give a Button a Multiple function. (ie; make it set a cookie AND navigate to another page)
This would GREATLY save time setting cookies and navigating through my site.

Thanks Alot! :thumbsup: :)

glenmac
03-08-2005, 01:13 PM
<input type = "button" onclick = "function1(); function2();">

DR.Wong
03-09-2005, 12:04 PM
Okay, now If I wanted a cookie set to a particular vale with a different value, would I have to write the setcookie script again, just with a different value, or is there a way of placing that on the button aswell.

eg : ...function1() + 'yes' ; function2()...

I know this wont work, its just to get the message accross.

Thank again! :thumbsup: :)

DR.Wong
03-10-2005, 07:03 AM
Uh... Anyone?

This is quite urgent, so if any of you guys know, please share...

Thanks! :thumbsup:

_Aerospace_Eng_
03-10-2005, 07:15 AM
y not have the variable yes be part of the function and pass it through there instead? can we see your code? you aren't helping us much with just giving vague examples

DR.Wong
03-19-2005, 06:14 AM
Okay, here is a rough example of what I want to do...

When the "yes" or "no" button is pressed, I want the browser to navigate to , lets say 'cookiecheck.htm'

Its a pretty simple thing, just I cant do it.



<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var expDays = 365;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var favorite = GetCookie('myoptions');

if (favorite != null) {
switch (favorite) {
case 'yes' : url = 'option1.htm'; // URL's
break;
case 'no' : url = 'option2.htm';
break;

}
window.location.href = url;

}
// End -->
</script>
</head>
<body>
<center><font face=verdana size=5 color=silver>Please select an option</font><br>
<hr>
<form>
<p align=left><table><tr><td>

<input type=button value="Yes" name="yes" onClick="SetCookie('myoptions', this.name, exp);"><br><br>
<input type=button value=" No " name="no" onClick="SetCookie('myoptions', this.name, exp);"><br>


</td></tr>
</table>
</form>
</p>
</body>
</html>


Think anyone can help? :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum