Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    having problem with adding class to obj

    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 .

    Code:
    {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 .

    Code:
    // 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 .

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by mehdi_php View Post
    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
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •