...

View Full Version : having problem with adding class to obj



mehdi_php
11-26-2008, 08:10 AM
i have a problem . when i select an item it's load with ajax i have div object with an Id attribute inside it . the id is retrieved from database an in foreach loop i iterate this div .


{section name=all loop=$article }
<div id="{$article[all].xarticleid}" style="cursor:pointer" onclick="get_article_body(this);" class="">
{/section}

ok . after i click the item it's fetch the article body from db an show it in another div . it's works . i want to change the div inside text each time it's select so i do that .


// Function that starts the Ajax process:
function get_article_body(obj) {

obj.addClass('Ared');

if (ajax) {

// Call the PHP script.
// Use the GET method.
// Pass the zip code in the URL.
ajax.open('get', '../ajax/get_article_body.php?id=' + encodeURIComponent(obj.id));

// Function that handles the response:
ajax.onreadystatechange = handle_stores;

// Send the request:
ajax.send(null);

return false;

} else { // Can't use Ajax!
return true;
}

} // End of get_stores() function.

// Function that handles the response from the PHP script:
function handle_stores() {

document.getElementById('desc').innerHTML = '<div align="right"><img src="../images/loading.gif"> &nbsp;Loading Content ...</div>';
// If everything's OK:
if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

// Check the length of the response:
if (ajax.responseText.length > 10) {

// Send the response, in object form,
// to the show_stores() function:
show_stores(eval('(' + ajax.responseText + ')'));

} else {
document.getElementById('desc').innerHTML = 'Loading Content ...<img src="loading.gif">';
}

}

} // End of handle_stores() function.

// Function that shows the list of stores:
function show_stores(stores) {

// Initialize a string:
var message = '';

// Get each store:
for (var i = 0 ; i < stores.length ; i++) {

// Add to the string:
message +=
'<p>' + stores[i].articlebody + '<br />'

}

// Place the string in the page:
document.getElementById('desc').innerHTML = message;

} // End of show_stores() function.


but i got an error . and when i get rid of that line (obj.addClass('Ared')) it's works fine again .

shyam
11-26-2008, 03:14 PM
but i got an error . and when i get rid of that line (obj.addClass('Ared')) it's works fine again .

whatever gave you the idea that addClass is a method defined on a div element? you have to user the className property to set the class



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum