SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX - adding/deleting table rows in IE problem...

    First of all, my code works in FF and Opera... In IE it gives me an unknown runtime error...

    Basically what my code does is extract data submitted via a form and adds it to the database. It then updates a table and a couple of divs on the page...

    Code:
    var AJAXForms = false;
    var LastField = null;
    var isIE = false;
    // on !IE we only have to initialize it once
    if (window.XMLHttpRequest) {
        AJAXForms = new XMLHttpRequest();
    }
    function ajax_addProduct(form,table,purchase_id) {
        if (window.XMLHttpRequest) {
            // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            AJAXForms = new ActiveXObject("Microsoft.XMLHTTP");
        }
    
        AJAXForms.onreadystatechange = function() { 
            if (AJAXForms.readyState == 4) {
                eval(AJAXForms.responseText);
                var tbody = document.getElementById(table).getElementsByTagName("TBODY")[0];
                var row = document.createElement("TR")
                var td1 = document.createElement("TD")
                td1.appendChild(document.createTextNode(res_product))
                var td2 = document.createElement("TD")
                td2.appendChild (document.createTextNode(res_price))
                var td3 = document.createElement("TD")
                td3.appendChild (document.createTextNode(res_commission))
                var td4 = document.createElement("TD")
                td4.innerHTML = '<a href="javascript:void(0);" onclick="ajax_deleteAddProductRow(this,\''+table+'\',\''+purchase_id+'\',\''+res_id+'\')"><img src="images/delete.png" border="0" /></a>';
                row.appendChild(td1);
                row.appendChild(td2);
                row.appendChild(td3);
                row.appendChild(td4);
                tbody.appendChild(row);
    
                form.product_name.value = "";
                form.price.value = "0.00";
                form.ongoing_date.value = "";
                form.ongoing_price.value = "";
                form.ongoing_interval.value = "";
            }
        };
    
        for (var i=0; i < form.product_select.length; i++) {
            if (form.product_select[i].checked) {
                var product_select = form.product_select[i].value;
            }
        } 
        if (product_select == "custom") {
            var product = form.product_name.value;
        } else {
            var product = form.product_id.value;
        }
        AJAXForms.open("GET", "modules/clients/ajax-add_product.php?purchase_id="+ purchase_id +"&product="+ product +"&price="+ form.price.value +"&ongoing_date="+ form.ongoing_date.value +"&ongoing_price="+ form.ongoing_price.value +"&ongoing_interval="+ form.ongoing_interval.value);
        AJAXForms.send(null);
    }
    This is a sample response:

    Code:
    var res_id = '849';
    var res_product = 'Test Product';
    var res_price = '$10.00';
    var res_commission = '$100.00';
    document.getElementById('price').innerHTML = '$40.00';
    document.getElementById('commission').innerHTML = '$400.00';
    When I comment out the two document.getElementById it works once... If I try submit the form again without reloading the page, it doesn't work.

    Any ideas what is wrong? Liek I said, it works in FF and Opera.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are the elements price and commision? innerHTML shouldn't be used like this, as its not always supported across all elements.

    If its text you are displaying, either use value or appendChild(document.createTextNode('value'));

    ie

    Code:
    document.getElementById('price').appendChild(document.createTextNode('$40.00'));
    document.getElementById('commission').appendChild(document.createTextNode('$400.00'));


  3. #3
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Gav!

    The elements are DIVs... I tried your code and what it does is it adds to the div instead of replacing the current text with the new value...

    Also, still not working in IE....

  4. #4
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One other thing... Even though it still isn't working in IE, I'm getting a new error....

    Unexpected call to method or property access.

  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry for the delay. What line does this new error point to?

    Also, if you want to replace the current value, its best to use

    Code:
    var price = document.getElementById('price');
    var commission = document.getElementById('commission');
    price.innerHTML = '';
    price.appendChild(document.createTextNode('$40.00'));
    commission.innerHTML = '';
    commission.appendChild(document.createTextNode('$400.00'));



Bookmarks

Posting Permissions

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