Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:15:03+00:00 2026-06-09T23:15:03+00:00

I have a function to set cookies, and i have .bind() set on some

  • 0

I have a function to set cookies, and i have .bind() set on some of my links so that they trigger the cookie function when clicked. Right now, when they are clicked no cookie is set. I’ve spent hours on this and cant figure it out.

<script type="text/javascript"> function createCookie(name,value,days) { 
if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    var expires = ";
 expires=" + date.toGMTString();
}
else {
    var expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}
$("a#en").bind("click", function () {
    createCookie('TR_LNG', 'en', 90);
});
$("a#fr").bind("click", function () {
    createCookie('TR_LNG', 'fr', 90);
});
$("a#de").bind("click", function () {
    createCookie('TR_LNG', 'de', 90);
});
$("a#ja").bind("click", function () {
    createCookie('TR_LNG', 'ja', 90);
});
$("a#pl").bind("click", function () {
    createCookie('TR_LNG', 'pl', 90);
});
$("a#es").bind("click", function () {
    createCookie('TR_LNG', 'es', 90);
});
</script> 

HTML

<div id="langselectsplash" class="langselectsplash">
    <div id="select">
        <img src="http://mysite.org/wp-content/uploads/2012/08/sarvalogo2.png"
        />
        <p>
            <style>
            #tr_setdeflang {
                display:none;
            }

            </style>
            <div class="no_translate transposh_flags">
                <a id="en" href="/about/" class="tr_active">English</a>
                <a id="fr" href="/fr/about/">Français</a>
                <a id="de" href="/de/about/">Deutsch</a>
                <a id="ja" href="/ja/about/">日本語</a>
                <a id="pl" href="/pl/about/">Polski</a>
                <a id="es" href="/es/about/">Español</a>
            </div>
        </p>
    </div>
</div>
<div id="langsplashfade"></div>

The PHP code that outputs the above:

<?php
echo "<script type=\"text/javascript\"> function createCookie(name,value,days) { \nif (days) { \nvar date = new Date();\n date.setTime(date.getTime()+(days*24*60*60*1000));\n var expires = \";\n expires=\"+date.toGMTString();\n} else { \nvar expires = \"\";}document.cookie = name+\"=\"+value+expires+\"; path=/\";}\n";
foreach ($args as $langrecord) {
    echo "$(\"a#{$langrecord['isocode']}\").bind(\"click\", function() {createCookie('TR_LNG','{$langrecord['isocode']}',90);});\n";
}
echo "</script>";
?>
   <?php
echo " <div id=\"langselectsplash\" class=\"langselectsplash\"><div id=\"select\"><img src=\"http://mysite.org/wp-content/uploads/2012/08/sarvalogo2.png\" /><p>";
?>
           <?php
echo "<style>#tr_setdeflang{display:none;}</style><div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >";
foreach ($args as $langrecord) {
    echo "<a id=\"{$langrecord['isocode']}\" href=\"{$langrecord['url']}\"" . ($langrecord['active'] ? ' class="tr_active"' : '') . '>' . "{$langrecord['langorig']}</a>";
}
echo "</div>";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:15:05+00:00Added an answer on June 9, 2026 at 11:15 pm

    You need to put the code where you are binding events on the DOM ready event:

    $(document).ready(function(){
    //Your code
    });
    

    or

    $(function(){
    //Your code
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that I set custom key and value to it and
I have the following function that does string splitting: on splitText(aString, delimiter) set retVal
Is it possible to use jQuery's $.post function and have the cookies set in
I got a script like that (I use jQuery cookie js to set cookies)
I have some code that saves the user's ID as a cookie. It works
When I try to read my cookie that I have set something does not
I have a bunch of cookies set that I want to match against the
In my logout function, I have HttpContext.Current.Session.Abandon(); HttpContext.Current.Response.Cookies[ASP.NET_SessionId].Expires = DateTime.Now.AddYears(-30); I see that the
I have the following function set up to sequentially fade in divs (with class
If I have a function overload set similar to template<typename T> void f(T&& t,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.