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

  • Home
  • SEARCH
  • 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 6142943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:27:22+00:00 2026-05-23T18:27:22+00:00

<html> <script type=text/javascript> function createCookie(name,value,days) { if (days) { var date = new Date();

  • 0
<html>
<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=/";

};


function executeFunc()  {

    var cookieData=document.cookie.split(';');
    for(entry in cookieData)
    {
        createCookie(cookieData[entry],"",-1); //clear the cookie first
    }
    createCookie("node-1","1",365);
    createCookie("node-2","1",365);
    createCookie("node-3","1",365);

    alert("the cookie contains : " + document.cookie);

    var cookie=document.cookie.split(';');

        for(ele in cookie)
        {
            var node=cookie[ele].split('=');


            alert(node[0]);  //this prints the next node correctly
            var nodeId=document.getElementById(node[0]); //for the first 
                     //iteration i get the row in 
                     //nodeId correctly but for the next iterations, i get null, 
                     //althought the row exists. if i type in the row Id manually 
                     //it works, but if i use node[0] then it returns null !! :S
            alert("the node is : " + nodeId);

            alert(document.cookie);



        }


}


</script>
<body onLoad="executeFunc()">
<table>
<tbody>
<tr id="node-1">
    <td>im node 1</td>
</tr>
<tr id="node-2">
    <td>im node 2</td>
</tr>
<tr id="node-3">
    <td>im node 3</td>
</tr>
</tbody>
</table>

</body>
</html>

first of all i dint know how to run the above code on Jsfiddle and then link it to my question. sorry for that!!

In executeFunc() in javascript, i am spliting the cookie entries and extracting the names in “node” variable. then using this name, i get the row object and print it. when it loops for the first time, everything goes as planned but for the next iterations, alert(node[0]) prints the next entry in the cookie(i.e node-2) but nodeId=document.getElementById(node[0]) returns null. if i change it to nodeId=document.getElementById("node-2") it works fine. i dont knw wat the prblm is..you can test it by just copy pasting it…its the complete code!!
Thanks!!

  • 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-05-23T18:27:23+00:00Added an answer on May 23, 2026 at 6:27 pm

    Your cookie has a space in front of each identifier. Thus, it tries to look up " node-1" and doesn’t find it. You can see the spaces in this version of your code with quote marks around the alert text: http://jsfiddle.net/jfriend00/ZS3HB/.

    I’d suggest either revising the split to split('; ') or trim leading/trailing spaces off the identifiers before using them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My html: <script type=text/javascript> $(function() { $(#bt1).click(function() { var f = $(#form1); var formData
Can someone show me whats wrong with this: <html> <script type = text/javascript> function
look at this code, <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script> function change() {
This my javascript :- <script type =text/javascript> $(function() { $(#tabs).tabs({ cache: true ,fx: {
<!DOCTYPE html> <html lang=en> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js type=text/javascript></script> <script type=text/javascript>
I'm attempting to select all <script type=text/html> tags in a page. I use <script>
I have below html code <div id=divTest> Hello <input type=text id=txtID value= /> <input
The JS script: function ShowUploadingAnimation() { $('#info_msg').html(<div style=\padding-top: 15px; height: 50px;\ align=\center\><img id=\uploading-img\ /></div>);
I have this sample page: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8> <title>Ajax Page</title> <script
I have made a js function for including another Javascript in my html. I

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.