Forum Moderators: open
I can't seem to get it going, so I thought I'd post some code.
I am trying to have it so if the response.state==2, it creates a child element of a div on the page with an id.
Then when it reaches response.state==4, it can change the innerHTML of the div that was created in response.state==2.
if (ajaxRequest.readyState == 1)
{
var content = document.getElementById)'content');
var verifydiv = document.createElement('div');
verifydiv.innerHTML = "Verifying...";
verifydiv.setAttribute("id","verifydiv");
content.appendChild(verifydiv);
}
else if (ajaxRequest.readyState == 4)
{
var verifydiv = document.getElementById('verifydiv');
verifydiv.innerHTML = "Verified!";
}
Silly typo!
Just wondering if I can do this thing:
function showSingleWorkshop(workshopId)
{
startAjax('ajaxRequest');var content = document.getElementById('content');
var sswdiv = document.createElement('div');
sswdiv.setAttribute('id', 'sswdiv');
content.appendChild(sswdiv);
ajaxRequest.onreadystatechange = function()
{
if (ajaxRequest.readyState == 1)
{
sswdiv.innerHTML = "Loading";
}
else if (ajaxRequest.readyState == 4)
{
sswdiv.innerHTML = ajaxRequest.responseText;
}
}
var queryString = "?action=showSingleWorkshop" + "&workshopId=" + workshopId;
ajaxRequest.open("GET", "process.php" + queryString, true);
ajaxRequest.send(null);
}
Now in the process.php file, I have a link to another function in js:
function showWorkshopRegistrations(workshopId)
{
startAjax('ajaxRequest');
var sswdiv = document.getElementById('sswdiv');
var swrdiv = document.createElement('div');
swrdiv.setAttribute('id', 'swrdiv');
sswdiv.appendChild(swrdiv);
ajaxRequest.onreadystatechange = function()
{
if (ajaxRequest.readyState == 1)
{
swrdiv.innerHTML = "Loading";
}
else if (ajaxRequest.readyState == 4)
{
swrdiv.innerHTML = ajaxRequest.responseText;
}
}
var queryString = "?action=showWorkshopRegistrants" + "&workshopId=" + workshopId;
ajaxRequest.open("GET", "process.php" + queryString, true);
ajaxRequest.send(null);
}
So in effect I am making a tree. That the showSingleWorkshop is making the element: "sswdiv" and appending it to "content" (which is on the HTML page) and showWorkshopRegistrations is making "swrdiv" and appending it to "sswdiv". It doesn't seem to want to append to "sswdiv" as I think it is not hard coded into the html DOM. Is there a way I can do this tree thing?
I am not sure if the elements I created can affect outside that particular function