By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

removing a child node

omerbutt
100+
P: 638
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
Expand|Select|Wrap|Line Numbers
  1. file=allmethods.js
  2. var xmlHttpAddCol;
  3. function AddCol(action,q){
  4.     var url;
  5.     var inc ;
  6.     xmlHttpAddCol=GetXmlHttpObject();
  7.         if (xmlHttpAddCol==null){
  8.             alert ("Browser does not support HTTP Request");
  9.             return;
  10.         } 
  11.     if(action=="add"){
  12.         inc = parseInt(document.addfrm.count.value) + 1;
  13.         url="addcol.php?q="+inc+"&sid="+Math.random();
  14.         xmlHttpAddCol.onreadystatechange=SCAddCol;
  15.         xmlHttpAddCol.open("GET",url,true);
  16.         xmlHttpAddCol.send(null);
  17.     }else if(action=="del"){
  18.         var field=q-1;
  19.         removediv();
  20.         document.getElementById("picture"+field).style.visibility='visible';
  21.         alert("field"+field);
  22.         alert("q"+q);
  23.         if(field>0){
  24.             document.getElementById("tdpicture"+field).style.display='inline';
  25.         }
  26.         inc = parseInt(document.addfrm.count.value) - 1;
  27.         document.getElementById('count').value=inc;
  28.     }
  29. }
  30. function removediv(){
  31.     var divno = document.getElementById('count').value;
  32.     var d = document.getElementById('txtHint'+0);
  33.     var divname ='txtHint'+divno;
  34.     var olddiv =document.getElementById(divname);
  35.     d.removeChild(olddiv);
  36. }
  37. function SCAddCol(){ 
  38.     if (xmlHttpAddCol.readyState==4 || xmlHttpAddCol.readyState=="complete"){    
  39.         var a=xmlHttpAddCol.responseText;
  40.         var b=a.split("|");
  41.         var field=b[1];
  42.         if(field!=0){
  43.             document.getElementById("tdpicture"+field).style.display='none';
  44.         }
  45.         var ni=document.getElementById('txtHint0');
  46.         var numi = document.getElementById('count');
  47.         var inc = parseInt(document.addfrm.count.value) + 1;
  48.         var num = inc;
  49.         numi.value = field+1;
  50.         var resdiv = document.createElement('div');
  51.         alert(resdiv);
  52.         var divIdName = 'txthint'+num;
  53.         resdiv.setAttribute('id',divIdName);
  54.         ni.appendChild(resdiv);
  55.         document.getElementById(divIdName).innerHTML=b[0];
  56.         document.addfrm.count.value = inc;
  57.         document.getElementById("picture"+field).style.visibility='hidden';
  58.     } 
  59. }
  60.  
Expand|Select|Wrap|Line Numbers
  1. file=add-product-details.php
  2.                 <form name="addfrm" id="addfrm" method="post" action="add-product-version.php">
  3.                   <table cellspacing="1" cellpadding="5" border="1" align="center" width="1002" class="tablebg">
  4.                     <input name="spannumber" id="spannumber" type="hidden" value="0" />
  5.                     <input name="count" id="count" type="hidden" value="0" />
  6.                     <tr><td align="center" class="td_head"><strong>Add Product</strong></td></tr>
  7.                     <tr><td align="left" class="tdTitle"><?=$cat_name;?> Series --> <?=$prod_name;?></td></tr>
  8.                     <tr>
  9.                         <td align="left" class="tdTitle">
  10.                             <table cellspacing="0" cellpadding="0" border="0" align="left">
  11.                                 <tr>
  12.                                     <td align="left" class="tdTitle">
  13.                                         <table cellspacing="1" cellpadding="5" border="0" align="left">
  14.                                             <tr><td align="left" class="tdTitle" colspan="2">Version<br /><input type="text" name="versionname[]" id="versionname[]" class="input" /> <input type="button" name="picture0" id="picture0" class="button" value="Add Column" onClick="javascript:AddCol('add');" /></td></tr>
  15.                                             <tr>
  16.                                                 <td align="left" valign="top" width="75">Description : </td>
  17.                                                 <td align="left" valign="top"><textarea type="text" name="prod_description[]" id="prod_description[]" rows="8" class="textarea"></textarea></td>
  18.                                             </tr>
  19.                                             <tr>
  20.                                                 <td align="left" valign="top">Features : </td>
  21.                                                 <td align="left" valign="top"><textarea type="text" name="prod_feature[]" id="prod_feature[]" rows="8" class="textarea"></textarea></td>
  22.                                             </tr>
  23.                                             <tr>
  24.                                                 <td align="left" valign="middle">Code : </td>
  25.                                                 <td align="left" valign="middle"><input type="text" name="prod_code[]" id="prod_code[]" class="input" /></td>
  26.                                             </tr>
  27.                                             <tr>
  28.                                                 <td align="left" valign="middle">Price : </td>
  29.                                                 <td align="left" valign="middle"><input type="text" name="prod_price[]" id="prod_price[]" class="input" /></td>
  30.                                             </tr>
  31.                                             <tr>
  32.                                                 <td align="left" valign="middle">Bend : </td>
  33.                                                 <td align="left" valign="middle"><input type="text" name="prod_bend[]" id="prod_bend[]" class="input" /></td>
  34.                                             </tr>
  35.                                             <tr>
  36.                                                 <td align="left" valign="middle">2 Checkout ID : </td>
  37.                                                 <td align="left" valign="middle"><input type="text" name="prod_co_id" id="prod_co_id" class="input" /></td>
  38.                                             </tr>
  39.                                         </table>
  40.                                     </td>
  41.                                 </tr>
  42.                             </table>
  43.                             <div id="txtHint0" style="border:1px solid #FF0000;"></div>
  44.                         </td>
  45.                     </tr>
  46.                     <tr>
  47.                         <td align="left" class="tdTitle"><input name="Submit" id="Submit" type="submit" class="button" value="Submit" title="Submit" /></td>
  48.                     </tr>
  49.                   </table>
  50.                 </form>
  51.  
  52.  
Expand|Select|Wrap|Line Numbers
  1. FILE=addcol.php
  2. <td align="left" class="tdTitle">
  3.     <table cellspacing="1" cellpadding="5" border="0" align="left">
  4.         <tr>
  5.             <td align="left" class="tdTitle" colspan="2">
  6.                 <table cellspacing="0" cellpadding="0" border="0" align="left">
  7.                     <tr>
  8.                         <td align="left" valign="middle">Version<br /><input type="text" name="versionname[]" id="versionname[]" class="input" />&nbsp;</td>
  9.                         <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>
  10.                         <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','<?=$_GET['q'];?>');" /></td>
  11.                     </tr>
  12.                 </table>
  13.                </td>
  14.            </tr>
  15.         <tr>
  16.             <td align="left" valign="top" width="75">Description : </td>
  17.             <td align="left" valign="top"><textarea type="text" name="prod_description[]" id="prod_description[]" rows="8" class="textarea"></textarea></td>
  18.         </tr>
  19.         <tr>
  20.             <td align="left" valign="top">Features : </td>
  21.             <td align="left" valign="top"><textarea type="text" name="prod_feature[]" id="prod_feature[]" rows="8" class="textarea"></textarea></td>
  22.         </tr>
  23.         <tr>
  24.             <td align="left" valign="middle">Code : </td>
  25.             <td align="left" valign="middle"><input type="text" name="prod_code[]" id="prod_code[]" class="input" /></td>
  26.         </tr>
  27.         <tr>
  28.             <td align="left" valign="middle">Price : </td>
  29.             <td align="left" valign="middle"><input type="text" name="prod_price[]" id="prod_price[]" class="input" /></td>
  30.         </tr>
  31.         <tr>
  32.             <td align="left" valign="middle">Bend : </td>
  33.             <td align="left" valign="middle"><input type="text" name="prod_bend[]" id="prod_bend[]" class="input" /></td>
  34.         </tr>
  35.         <tr>
  36.             <td align="left" valign="middle">2 Checkout ID : </td>
  37.             <td align="left" valign="middle"><input type="text" name="prod_co_id[]" id="prod_co_id[]" class="input" /></td>
  38.         </tr>
  39.     </table>
  40.     <div id="txtHint<?= $_GET['q']?>"></div>
  41. </td>
  42. <? $a=$_GET['q'];
  43.     $a=$a-1;
  44.     echo "|".$a;
  45. ?>
  46.  
Apr 25 '08 #1
Share this Question
Share on Google+
20 Replies


acoder
Expert Mod 15k+
P: 16,027
What line is this error occurring on?
Apr 25 '08 #2

omerbutt
100+
P: 638
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.
Expand|Select|Wrap|Line Numbers
  1. var d = document.getElementById('txtHint'+0);
  2.  
thanks for any help in advance,
regards
omer
Apr 25 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Why "txtHint"+0? Why not "txtHint0"?
Apr 25 '08 #4

omerbutt
100+
P: 638
Why "txtHint"+0? Why not "txtHint0"?
nops sir it is still with that abnormal behaviour it wont make any difference like that :(
Apr 25 '08 #5

gits
Expert Mod 5K+
P: 5,390
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
Apr 26 '08 #6

omerbutt
100+
P: 638
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"
Expand|Select|Wrap|Line Numbers
  1. <div id="txtHint0" ></div>
  2.  
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
Apr 26 '08 #7

acoder
Expert Mod 15k+
P: 16,027
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?
Apr 26 '08 #8

gits
Expert Mod 5K+
P: 5,390
hmmm ... i just actually see the following strange thing from one more quick look:

you create an id while adding:

Expand|Select|Wrap|Line Numbers
  1. var divIdName = 'txthint' + num;
  2. resdiv.setAttribute( 'id', divIdName );
  3.  
and later on you try to use 'txtHint' ... but the id should be case sensitive and so may be the problem?

kind regards
Apr 26 '08 #9

omerbutt
100+
P: 638
hmmm ... i just actually see the following strange thing from one more quick look:

you create an id while adding:

Expand|Select|Wrap|Line Numbers
  1. var divIdName = 'txthint' + num;
  2. resdiv.setAttribute( 'id', divIdName );
  3.  
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
Apr 26 '08 #10

gits
Expert Mod 5K+
P: 5,390
i know ... but in line 33 you create a divname:

Expand|Select|Wrap|Line Numbers
  1. var divname ='txtHint'+divno;
  2.  
and isn't that a div IN the parent? that you try to refer to? to remove it then from the parent?

kind regards
Apr 26 '08 #11

omerbutt
100+
P: 638
i know ... but in line 33 you create a divname:

Expand|Select|Wrap|Line Numbers
  1. var divname ='txtHint'+divno;
  2.  
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"in 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
Expand|Select|Wrap|Line Numbers
  1. var divno =q; 
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
Apr 26 '08 #12

gits
Expert Mod 5K+
P: 5,390
so the alerts you did are what you expected? ... then please post what the following alert says when you want to remove a node:

Expand|Select|Wrap|Line Numbers
  1. function removediv(){
  2.     var divno = document.getElementById('count').value;
  3.     var d = document.getElementById('txtHint'+0);
  4.  
  5.     alert(d.innerHTML);    
  6.  
  7.     var divname ='txtHint'+divno;
  8.     var olddiv =document.getElementById(divname);
  9.     d.removeChild(olddiv);
  10. }
Apr 26 '08 #13

omerbutt
100+
P: 638
so the alerts you did are what you expected? ... then please post what the following alert says when you want to remove a node:

Expand|Select|Wrap|Line Numbers
  1. function removediv(){
  2.     var divno = document.getElementById('count').value;
  3.     var d = document.getElementById('txtHint'+0);
  4.  
  5.     alert(d.innerHTML);    
  6.  
  7.     var divname ='txtHint'+divno;
  8.     var olddiv =document.getElementById(divname);
  9.     d.removeChild(olddiv);
  10. }
according to the above given code the alert gives me the html code for the last created div here is the code
Expand|Select|Wrap|Line Numbers
  1. <div id="txthint1"><td class="tdTitle" align="left" width="600">
  2.     <table align="left" border="0" cellpadding="5" cellspacing="1" width="300">
  3.         <tbody><tr>
  4.             <td class="tdTitle" colspan="2" align="left">
  5.                 <table align="left" border="0" cellpadding="0" cellspacing="0">
  6.                     <tbody><tr>
  7.                         <td align="left" valign="middle">Version<br><input name="versionname[]" id="versionname[]" class="input" type="text">&nbsp;</td>
  8.                         <td id="tdpicture1" align="left" valign="middle"><br><input name="picture1" id="picture1" class="button" value="Add Column" onclick="AddCol('add');" type="button"></td>
  9.                         <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>
  10.                     </tr>
  11.                 </tbody></table>
  12.                </td>
  13.            </tr>
  14.         <tr>
  15.             <td align="left" valign="top" width="75">Description : </td>
  16.             <td align="left" valign="top"><textarea type="text" name="prod_description[]" id="prod_description[]" rows="8" class="textarea"></textarea></td>
  17.         </tr>
  18.         <tr>
  19.             <td align="left" valign="top">Features : </td>
  20.             <td align="left" valign="top"><textarea type="text" name="prod_feature[]" id="prod_feature[]" rows="8" class="textarea"></textarea></td>
  21.         </tr>
  22.         <tr>
  23.             <td align="left" valign="middle">Code : </td>
  24.             <td align="left" valign="middle"><input name="prod_code[]" id="prod_code[]" class="input" type="text"></td>
  25.         </tr>
  26.         <tr>
  27.             <td align="left" valign="middle">Price : </td>
  28.             <td align="left" valign="middle"><input name="prod_price[]" id="prod_price[]" class="input" type="text"></td>
  29.         </tr>
  30.         <tr>
  31.             <td align="left" valign="middle">Bend : </td>
  32.             <td align="left" valign="middle"><input name="prod_bend[]" id="prod_bend[]" class="input" type="text"></td>
  33.         </tr>
  34.         <tr>
  35.             <td align="left" valign="middle">2 Checkout ID : </td>
  36.             <td align="left" valign="middle"><input name="prod_co_id[]" id="prod_co_id[]" class="input" type="text"></td>
  37.         </tr>
  38.     </tbody></table>
  39. </td>
  40. </div>
  41.  
Apr 26 '08 #14

gits
Expert Mod 5K+
P: 5,390
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
Apr 26 '08 #15

omerbutt
100+
P: 638
so the alerts you did are what you expected? ... then please post what the following alert says when you want to remove a node:

Expand|Select|Wrap|Line Numbers
  1. function removediv(){
  2.     var divno = document.getElementById('count').value;
  3.     var d = document.getElementById('txtHint'+0);
  4.  
  5.     alert(d.innerHTML);    
  6.  
  7.     var divname ='txtHint'+divno;
  8.     var olddiv =document.getElementById(divname);
  9.     d.removeChild(olddiv);
  10. }
hey gits just when i posted the last reply i saw the main error which is in the very first line see the id of the div :D it is "txthint1 not txtHint1 :D man that was very common but irritating mistake and was occurin in the mozilla because mozilla is case sensitive and explorer is not thats why it was deleting in the IE but not mozilla thanks to you gits you made a goooood ALERT() cheers many thanks
regards,
omer
Apr 26 '08 #16

omerbutt
100+
P: 638
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
:D yeah i just got late poting the reply but i also saw the error and mentioned in my post any ways thanks aloots Gits
You are the MAN ;)
regards,
omer
Apr 26 '08 #17

gits
Expert Mod 5K+
P: 5,390
no problem ... the alert just showed you what i was trying to explain before :) ... glad to hear you got it working now :)

kind regards
Apr 26 '08 #18

omerbutt
100+
P: 638
no problem ... the alert just showed you what i was trying to explain before :) ... glad to hear you got it working now :)

kind regards
:) thanks a bundle :)
regards,
omer
Apr 26 '08 #19

acoder
Expert Mod 15k+
P: 16,027
Good spot, gits.
that was very common but irritating mistake and was occurin in the mozilla because mozilla is case sensitive and explorer is not thats why it was deleting in the IE but not mozilla
That's shoddy by IE. JavaScript is case-sensitive, not case-insensitive like VB.
Apr 26 '08 #20

omerbutt
100+
P: 638
Good spot, gits.
That's shoddy by IE. JavaScript is case-sensitive, not case-insensitive like VB.
:) what to say ?...... any ways thanks alot guys ,
regards,
omer
Apr 28 '08 #21

Post your reply

Sign in to post your reply or Sign up for a free account.