removing a child node

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    removing a child node

    hi there i am making an application in which i have to populate columns that consist of some textfields and some input boxes the problem is at the mozilla's end, it creates a new node and appends the new created or child node to the parent node it is working fine to the point of addition in the Explorer And Mozzila but when it comes to deleting the column it still works perfect in explorer without any javascript or other error but when i try to use Mozzila it gives me error.
    the error code is here
    Node was not found" code: "8
    why is that so i cant understand if it cant find the node then it means tha the name i am providing it is not the right one,but if it is not the right one then how come it could delete it in the explorer
    here is my code for that work any help would be highly appreciated
    [code=javascript]file=allmethods .js
    var xmlHttpAddCol;
    function AddCol(action,q ){
    var url;
    var inc ;
    xmlHttpAddCol=G etXmlHttpObject ();
    if (xmlHttpAddCol= =null){
    alert ("Browser does not support HTTP Request");
    return;
    }
    if(action=="add "){
    inc = parseInt(docume nt.addfrm.count .value) + 1;
    url="addcol.php ?q="+inc+"&sid= "+Math.random() ;
    xmlHttpAddCol.o nreadystatechan ge=SCAddCol;
    xmlHttpAddCol.o pen("GET",url,t rue);
    xmlHttpAddCol.s end(null);
    }else if(action=="del "){
    var field=q-1;
    removediv();
    document.getEle mentById("pictu re"+field).styl e.visibility='v isible';
    alert("field"+f ield);
    alert("q"+q);
    if(field>0){
    document.getEle mentById("tdpic ture"+field).st yle.display='in line';
    }
    inc = parseInt(docume nt.addfrm.count .value) - 1;
    document.getEle mentById('count ').value=inc;
    }
    }
    function removediv(){
    var divno = document.getEle mentById('count ').value;
    var d = document.getEle mentById('txtHi nt'+0);
    var divname ='txtHint'+divn o;
    var olddiv =document.getEl ementById(divna me);
    d.removeChild(o lddiv);
    }
    function SCAddCol(){
    if (xmlHttpAddCol. readyState==4 || xmlHttpAddCol.r eadyState=="com plete"){
    var a=xmlHttpAddCol .responseText;
    var b=a.split("|");
    var field=b[1];
    if(field!=0){
    document.getEle mentById("tdpic ture"+field).st yle.display='no ne';
    }
    var ni=document.get ElementById('tx tHint0');
    var numi = document.getEle mentById('count ');
    var inc = parseInt(docume nt.addfrm.count .value) + 1;
    var num = inc;
    numi.value = field+1;
    var resdiv = document.create Element('div');
    alert(resdiv);
    var divIdName = 'txthint'+num;
    resdiv.setAttri bute('id',divId Name);
    ni.appendChild( resdiv);
    document.getEle mentById(divIdN ame).innerHTML= b[0];
    document.addfrm .count.value = inc;
    document.getEle mentById("pictu re"+field).styl e.visibility='h idden';
    }
    }
    [/code]

    [code=html]file=add-product-details.php
    <form name="addfrm" id="addfrm" method="post" action="add-product-version.php">
    <table cellspacing="1" cellpadding="5" border="1" align="center" width="1002" class="tablebg" >
    <input name="spannumbe r" id="spannumber " type="hidden" value="0" />
    <input name="count" id="count" type="hidden" value="0" />
    <tr><td align="center" class="td_head" ><strong>Add Product</strong></td></tr>
    <tr><td align="left" class="tdTitle" ><?=$cat_name;? > Series --> <?=$prod_name;? ></td></tr>
    <tr>
    <td align="left" class="tdTitle" >
    <table cellspacing="0" cellpadding="0" border="0" align="left">
    <tr>
    <td align="left" class="tdTitle" >
    <table cellspacing="1" cellpadding="5" border="0" align="left">
    <tr><td align="left" class="tdTitle" colspan="2">Ver sion<br /><input type="text" name="versionna me[]" id="versionnam e[]" class="input" /> <input type="button" name="picture0" id="picture0" class="button" value="Add Column" onClick="javasc ript:AddCol('ad d');" /></td></tr>
    <tr>
    <td align="left" valign="top" width="75">Desc ription : </td>
    <td align="left" valign="top"><t extarea type="text" name="prod_desc ription[]" id="prod_descri ption[]" rows="8" class="textarea "></textarea></td>
    </tr>
    <tr>
    <td align="left" valign="top">Fe atures : </td>
    <td align="left" valign="top"><t extarea type="text" name="prod_feat ure[]" id="prod_featur e[]" rows="8" class="textarea "></textarea></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >Code : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_code[]" id="prod_code[]" class="input" /></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >Price : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_pric e[]" id="prod_price[]" class="input" /></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >Bend : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_bend[]" id="prod_bend[]" class="input" /></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >2 Checkout ID : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_co_i d" id="prod_co_id " class="input" /></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <div id="txtHint0" style="border:1 px solid #FF0000;"></div>
    </td>
    </tr>
    <tr>
    <td align="left" class="tdTitle" ><input name="Submit" id="Submit" type="submit" class="button" value="Submit" title="Submit" /></td>
    </tr>
    </table>
    </form>

    [/code]
    [code=html]FILE=addcol.php
    <td align="left" class="tdTitle" >
    <table cellspacing="1" cellpadding="5" border="0" align="left">
    <tr>
    <td align="left" class="tdTitle" colspan="2">
    <table cellspacing="0" cellpadding="0" border="0" align="left">
    <tr>
    <td align="left" valign="middle" >Version<br /><input type="text" name="versionna me[]" id="versionnam e[]" class="input" />&nbsp;</td>
    <td align="left" valign="middle" id="tdpicture<? =$_GET['q'];?>"><br /><input type="button" name="picture<? =$_GET['q'];?>" id="picture<?=$ _GET['q'];?>" class="button" value="Add Column" onclick="AddCol ('add');" /></td>
    <td align="left" valign="middle" id="tddelete<?= $_GET['q'];?>"><br /><input type="button" name="delete<?= $_GET['q'];?>" id="delete<?=$_ GET['q'];?>" class="button" value="Delete Column" onclick="AddCol ('del','<?=$_GE T['q'];?>');" /></td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="left" valign="top" width="75">Desc ription : </td>
    <td align="left" valign="top"><t extarea type="text" name="prod_desc ription[]" id="prod_descri ption[]" rows="8" class="textarea "></textarea></td>
    </tr>
    <tr>
    <td align="left" valign="top">Fe atures : </td>
    <td align="left" valign="top"><t extarea type="text" name="prod_feat ure[]" id="prod_featur e[]" rows="8" class="textarea "></textarea></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >Code : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_code[]" id="prod_code[]" class="input" /></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >Price : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_pric e[]" id="prod_price[]" class="input" /></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >Bend : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_bend[]" id="prod_bend[]" class="input" /></td>
    </tr>
    <tr>
    <td align="left" valign="middle" >2 Checkout ID : </td>
    <td align="left" valign="middle" ><input type="text" name="prod_co_i d[]" id="prod_co_id[]" class="input" /></td>
    </tr>
    </table>
    <div id="txtHint<?= $_GET['q']?>"></div>
    </td>
    <? $a=$_GET['q'];
    $a=$a-1;
    echo "|".$a;
    ?>
    [/code]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    What line is this error occurring on?

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      Originally posted by acoder
      What line is this error occurring on?
      it is in the javascript code line 32 where i am trying to make an object for the parentdiv and then remove the child node of that div.
      [code=javascript]
      var d = document.getEle mentById('txtHi nt'+0);
      [/code]
      thanks for any help in advance,
      regards
      omer

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Why "txtHint"+0 ? Why not "txtHint0"?

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          Originally posted by acoder
          Why "txtHint"+0 ? Why not "txtHint0"?
          nops sir it is still with that abnormal behaviour it wont make any difference like that :(

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            have you tried to alert the result from line 32 ... may be the error would more likely be with line 34 where you try the next getElementById( ) with a dynamic divname ...

            so please - just have a look whether it is really line 32 ...

            knd regards

            Comment

            • omerbutt
              Contributor
              • Nov 2006
              • 638

              #7
              Originally posted by gits
              have you tried to alert the result from line 32 ... may be the error would more likely be with line 34 where you try the next getElementById( ) with a dynamic divname ...

              so please - just have a look whether it is really line 32 ...

              knd regards
              yes sir i have checked it and it do alerts the object of that olddiv on the line 34 but on alerting "variable d" it says that it is undefined so i think the error is on the line 32 where it is creating the object of the div "txtHint0" which is hard coded means the main div in which i am populating all the divs .... :(, and thats no way the browser is behaving, lemme explain the scenario once again if i missed some thing back. i have made a div in the main page "add-product-details.php"
              [code=html]
              <div id="txtHint0" ></div>
              [/code]
              now i have a button on this same page "Add Column" which onclick calls a AJAX funtion which gets the html response from another page "addcol.php "
              and puts it into that <div id='txtHint0'></div> throoguh which another same column is populated next to the first column and the button of the "Add column" disappears from the first column and appears on the new column to populate another column if needed and so on , every thing is going fine till the adding process at both ends Mozilla and IE but when it comes to deleting it gives me the same sick error,
              i hope so i have quit elaborated the problem , would be no more confusion regarding to the scenario,
              hope to get a positive reply,
              regards,
              omer

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                When you're ready to delete (and the error occurs when you press delete), check the contents of the txtHint0 div by using e.g. Firebug. What are the contents at that point?

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  hmmm ... i just actually see the following strange thing from one more quick look:

                  you create an id while adding:

                  [CODE=javascript]var divIdName = 'txthint' + num;
                  resdiv.setAttri bute( 'id', divIdName );
                  [/CODE]
                  and later on you try to use 'txtHint' ... but the id should be case sensitive and so may be the problem?

                  kind regards

                  Comment

                  • omerbutt
                    Contributor
                    • Nov 2006
                    • 638

                    #10
                    Originally posted by gits
                    hmmm ... i just actually see the following strange thing from one more quick look:

                    you create an id while adding:

                    [CODE=javascript]var divIdName = 'txthint' + num;
                    resdiv.setAttri bute( 'id', divIdName );
                    [/CODE]
                    and later on you try to use 'txtHint' ... but the id should be case sensitive and so may be the problem?

                    kind regards
                    good to see you here gits :) well these two lines that you coded are used to assign the id to a new div that is created IN the "txtHint0" that is the main div or the parent div you can and the error is not on the line 32 where i try to use the var d for holding the object for the main div i.e txtHint0 it says that it is undefined

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5390

                      #11
                      i know ... but in line 33 you create a divname:

                      [CODE=javascript]var divname ='txtHint'+divn o;
                      [/CODE]
                      and isn't that a div IN the parent? that you try to refer to? to remove it then from the parent?

                      kind regards

                      Comment

                      • omerbutt
                        Contributor
                        • Nov 2006
                        • 638

                        #12
                        Originally posted by gits
                        i know ... but in line 33 you create a divname:

                        [CODE=javascript]var divname ='txtHint'+divn o;
                        [/CODE]
                        and isn't that a div IN the parent? that you try to refer to? to remove it then from the parent?

                        kind regards
                        yes the new created div is in the parent div,i have a hidden input field on the main page with the name count this field is incremented as the "AddColumn" button is pressed and that value is then passed through the ajax function to the addcol.php file where this value is concatinated with the div elements specially with the
                        "Add Column" and the "Delete Column" buttons ids and then passed through the onclik function of the Delete button , every new div created has the prefix "txtHint"+ a suffix that has a dynamic or you can say incrementing value which regards to the last div created means if initially you click on the add column button it increments the value in he count input field then the new div created has the name "txtHint1"i n which 1 is comming from the value of the counter and so on, now if i have to delete that column the same value 1 is passed through he function into that RemoveDiv(); function, the line which you mentioned tehre i was trying to get the value directly from the count field because i thaught that may be the value is not the right one you can change that line to
                        [code=javascript]var divno =q; [/code]
                        and yes one thing i just misguided you that it gives me error on the last line where i am trying to remove the child node where as i have alerted all the values and now all the values are being alerted means d,divno,divname and even the old div all when alerted no one is giving me error or blank value but as soon it comes to the last line it says that node not found
                        regards,
                        omer

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          so the alerts you did are what you expected? ... then please post what the following alert says when you want to remove a node:

                          [CODE=javascript]function removediv(){
                          var divno = document.getEle mentById('count ').value;
                          var d = document.getEle mentById('txtHi nt'+0);

                          alert(d.innerHT ML);

                          var divname ='txtHint'+divn o;
                          var olddiv =document.getEl ementById(divna me);
                          d.removeChild(o lddiv);
                          }[/CODE]

                          Comment

                          • omerbutt
                            Contributor
                            • Nov 2006
                            • 638

                            #14
                            Originally posted by gits
                            so the alerts you did are what you expected? ... then please post what the following alert says when you want to remove a node:

                            [CODE=javascript]function removediv(){
                            var divno = document.getEle mentById('count ').value;
                            var d = document.getEle mentById('txtHi nt'+0);

                            alert(d.innerHT ML);

                            var divname ='txtHint'+divn o;
                            var olddiv =document.getEl ementById(divna me);
                            d.removeChild(o lddiv);
                            }[/CODE]
                            according to the above given code the alert gives me the html code for the last created div here is the code
                            [code=html]
                            <div id="txthint1">< td class="tdTitle" align="left" width="600">
                            <table align="left" border="0" cellpadding="5" cellspacing="1" width="300">
                            <tbody><tr>
                            <td class="tdTitle" colspan="2" align="left">
                            <table align="left" border="0" cellpadding="0" cellspacing="0" >
                            <tbody><tr>
                            <td align="left" valign="middle" >Version<br><in put name="versionna me[]" id="versionnam e[]" class="input" type="text">&nb sp;</td>
                            <td id="tdpicture1 " align="left" valign="middle" ><br><input name="picture1" id="picture1" class="button" value="Add Column" onclick="AddCol ('add');" type="button"></td>
                            <td id="tddelete1" align="left" valign="middle" ><br><input name="delete1" id="delete1" class="button" value="Delete Column" onclick="AddCol ('del','1');" type="button"></td>
                            </tr>
                            </tbody></table>
                            </td>
                            </tr>
                            <tr>
                            <td align="left" valign="top" width="75">Desc ription : </td>
                            <td align="left" valign="top"><t extarea type="text" name="prod_desc ription[]" id="prod_descri ption[]" rows="8" class="textarea "></textarea></td>
                            </tr>
                            <tr>
                            <td align="left" valign="top">Fe atures : </td>
                            <td align="left" valign="top"><t extarea type="text" name="prod_feat ure[]" id="prod_featur e[]" rows="8" class="textarea "></textarea></td>
                            </tr>
                            <tr>
                            <td align="left" valign="middle" >Code : </td>
                            <td align="left" valign="middle" ><input name="prod_code[]" id="prod_code[]" class="input" type="text"></td>
                            </tr>
                            <tr>
                            <td align="left" valign="middle" >Price : </td>
                            <td align="left" valign="middle" ><input name="prod_pric e[]" id="prod_price[]" class="input" type="text"></td>
                            </tr>
                            <tr>
                            <td align="left" valign="middle" >Bend : </td>
                            <td align="left" valign="middle" ><input name="prod_bend[]" id="prod_bend[]" class="input" type="text"></td>
                            </tr>
                            <tr>
                            <td align="left" valign="middle" >2 Checkout ID : </td>
                            <td align="left" valign="middle" ><input name="prod_co_i d[]" id="prod_co_id[]" class="input" type="text"></td>
                            </tr>
                            </tbody></table>
                            </td>
                            </div>
                            [/code]

                            Comment

                            • gits
                              Recognized Expert Moderator Expert
                              • May 2007
                              • 5390

                              #15
                              so now ... have a look at the first line there:

                              [HTML]<div id="txthint1">< td class="tdTitle" align="left" width="600">
                              [/HTML]
                              so i assume now you want to remove that div? but as we see the id="txthint1' and not txtHint1 as you try to refer in your remove function?

                              kind regards

                              Comment

                              Working...