Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post

    Question Multiple Functions on a button

    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!
    -DR.Wong

    Wheres the food at?

  • #2
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <input type = "button" onclick = "function1(); function2();">

  • #3
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post

    Question

    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!
    -DR.Wong

    Wheres the food at?

  • #4
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post

    Question

    Uh... Anyone?

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

    Thanks!
    -DR.Wong

    Wheres the food at?

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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

  • #6
    Regular Coder DR.Wong's Avatar
    Join Date
    Jan 2005
    Posts
    360
    Thanks
    23
    Thanked 1 Time in 1 Post

    Question

    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.

    Code:
    <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?
    -DR.Wong

    Wheres the food at?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •