0

userDiv is a dynamically created button containing username and pic. Through a loop I have assigned the user's name as the div/button id. Onclick it goes to another page and assigns the name of the user to var name. However, when I get to the other page I seem to be unable to add any info. I have tried a couple of different methods (see below). I get an Object[object object] when I try to append the button itself for example and document.write just turns the screen blank altogether. If someone could explain this to me and offer a solution I would be grateful.

   userDiv.id=theName;
        userDiv.onclick=(function() {
            window.location.href = 'Createtask.html';
            alert($(this).attr("id"));
            name= $(this).attr("id");
            makeTask();
             });
};      
}

function makeTask(){
    function makeTask(){
    document.write(name);// blank screen
    //var userBtn= document.getElementById(name);
    //$("#singleUser").appendChild(userBtn);//Object [object object] error
    //var singleUser = document.getElementById('singleUser');
    //var greetUser = document.createElement("div");
    //greetUser.innerhtml='Yippee!';// can't do innerHTML of null
    //singleUser.appendChild(greetUser);//can't appendChild of null
    //$("#singleUser").html("Yippee");//no error, just nothing
}
}
Inkers
  • 219
  • 7
  • 27

1 Answers1

5

When the page exits, you can not do anything on the next page from the previous page with JavaScript. That is what the querystring and posts requests are for. You send data to the next page and it handles it.

window.location.href = 'Createtask.html?id=theID';

and on the next page you read the querystring and you can use that data.

Community
  • 1
  • 1
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • OK thanks a lot. Had a quick look. The pure javascript method looks a bit frightening! Will mark up when allowed. – Inkers Jan 18 '13 at 16:33
  • Most people use a serverside language to make the new page. Doing that right now. :) – epascarello Jan 18 '13 at 16:40
  • Using Phonegap so a bit limited in terms of php etc. – Inkers Jan 18 '13 at 16:41
  • For complete novices like me this is explaining it fairly well: http://www.htmlgoodies.com/beyond/javascript/article.php/3755006/How-to-Use-a-JavaScript-Query-String-Parser.htm – Inkers Jan 18 '13 at 16:54