Ok so… I’m trying to fetch a div’s content dynamically through a script from another page. Now, initially, it works great. But when I try to use the form in the generated div content, I get an error:
[code]Uncaught TypeError: object is not a function native runtime.js:213
Here’s the JS code for the page:
[code]function getAjax()
{
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else if (window.ActiveXObject)
return new ActiveXObject(“Microsoft.XMLHTTP”);
return null;
}
function startAddWebsite()
{
xmlhttp = getAjax();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4) document.getElementById(‘addWebsiteDiv’).innerHTML = xmlhttp.responseText;
};
xmlhttp.open(“POST”, “templates/add-website.php?sid=”+Math.random(), true);
xmlhttp.send(null);
}
function addWebsite()
{
xmlhttp = getAjax();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4) document.getElementById(‘addWebsiteDiv’).innerHTML = xmlhttp.responseText;
};
xmlhttp.open(“POST”, “templates/add-website.php?website=”+document.addWebsite.website.value+”&sid=”+Math.random(), true);
xmlhttp.send(null);
}
And here’s the add-website.php code:
[code]<? if (!$_GET[‘website’]) : ?>
<form name=”addWebsite” onsubmit=”this.addButton.onclick(); return false;”>
Add a website to your homepage: <input type=”text” name=”website” />
<input type=”button” name=”addButton” value=”Add” onclick=”addWebsite();” />
</form>
<? else : if ($_GET[‘website’])
{
$website = str_replace(‘javascript:’, ”, $_GET[‘website’]);
$seg = explode(“/”, $website);
$domain = $seg[2];
$website_result = mysql_query(“SELECT * FROM `websites` WHERE `url` = ‘$website'”);
$website_assoc = mysql_fetch_assoc($website_result);
if (mysql_num_rows($website_result))
mysql_query(“INSERT INTO `user_grid` (`user`, `website`) VALUES (‘1’, ‘{$website_assoc[‘id’]}’)”);
else
{
mysql_query(“INSERT INTO `websites` (‘url’, ‘domain’) VALUES (‘$website’, ‘$domain’)”);
$new_website = mysql_fetch_assoc(mysql_query(“SELECT * FROM `websites` WHERE `website` = ‘$website'”));
mysql_query(“INSERT INTO `user_grid` (`user`, `website`) VALUES (‘1’, ‘{$new_website[‘id’]}’)”);
}
echo ‘Added website successfully.’;
}
endif; ?>
What’s going wrong? I can’t really trace the error… I’m just starting with JS/AJAX, maybe I’m getting a wrong idea about something.