Web Analytics Made Easy -
StatCounter Problem removing child - CodingForum

Announcement

Collapse
No announcement yet.

Problem removing child

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem removing child

    Hello there, I have a problem and the only thing I have not done is yell 4 help.....

    I have a main window which opens a popup(window), before opening the window I create a javascript object, just communicate the window-popup, in the popup, I'm creating some "hidden fields" in the fly and append them to it's parent, a <input type=hidden name=something> everything works great, the fields are created, then the popup closes, still ok.....then if the user wants to go and modify any of the fields in the popup, then I open the popup, populate all the fields in the popup from the hidden fields, then remove the hidden fields.....works great, after the user enters the new data I "re-create the hidden fields" again w/the new data, this is just for avoiding duplicity.....

    so...everything works. gooooood....but....my friends, when the form(in the main window) is sent to the server, I store all those fields in the database....great...still ok...the problem is when I want to show that information back to the user...(a report view, or report Edit....) so I read the db, recreate the hidden fields and put them in the form same format, same parent, same name, same Id.....same values...when the form gets to the client, still everything ok, BUT.. when the user clicks in the area that opens the popup, the popup opens, populates all the form fields..FROM THE HIDDEN FIELDS, THEN TRIES TO DELETE THE HIDDEN FIELDS, THAT'S WHEN I'M HAVING THE PROBLEM....... ....I'm gettin a "Invalid argument" I checked the logic "same one that deleted the fields before", I displayed the value, id, name of the "parameter to the removeChild method" and everything looks good......... don't know what else to do... Next is the logic that creates the fields, and the logic that removes them....Just one more comment, there are some fields w/the same name but diff. Id. and some w/the same id but diff. name....still, the logic works when they "are created in the fly" but not when I create them in the server, before sending the form out to the client............an example to this can be found in www.ex-isb.com, then click the link, user/pwd is helper/helper thanks.......................

    again please remember that the problems occurs when I create the hidden fields in the server..........don't know if this can be the prob.. or not....what tha hell, i know nothing now.......


    those commented lines are just for debbuging

    function addHiddenField(name, id, value)
    {
    var holderField = document.getElementById("tmpFieldHolder");
    tmpField = document.createElement("input");
    tmpField.setAttribute("type","hidden");
    tmpField.setAttribute("name",name);
    tmpField.setAttribute("value",value);
    tmpField.setAttribute("id", id);
    holderField.appendChild(tmpField);
    //alert("Field added:" + name + "\nId:" + id + "\nvalue:" + value);

    }

    function removeHiddenField(dayToRemove)
    {
    var parent = document.getElementById("tmpFieldHolder");
    var tempChilds = parent.all.tags("input");
    var tempObject;
    var fieldPrefixName;
    var allFields = "ALL";
    var objById;
    //transverse all the childs and find the ones to delete
    var lengthOfChilds = tempChilds.length;
    // for(i=0;i<tempChilds.length;i++)
    // {
    // alert("fieldto be removed:"+tempChilds[i].name+"\nid:"+tempChilds[i].id+"\nvalue:"+tempChilds[i].value);
    // }
    for(idx=0;idx<lengthOfChilds;idx++)
    {
    tempObject = tempChilds[idx];
    fieldPrefixName = tempObject.name.substr(0,3);
    if(fieldPrefixName == dayToRemove)
    {
    //try
    //{
    //objById = getElementById(tempObject.id);
    parent.removeChild(tempObject);
    tempChilds = parent.all.tags("input");
    //}
    //catch(x)
    //{
    // alert(x)
    //tempChilds = parent.all.tags("input");
    //}

    }
    if(allFields == dayToRemove)
    {
    parent.removeChild(tempObject);
    tempChilds = parent.all.tags("input");
    }

    }
    }

  • #2
    Dunno...However, they'll solve it in a few minutes for you at the experts-exchange.com ...but I hope you do a better job of explanation.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

    Comment


    • #3
      Hey I killed my self for making such a good explanation

      Hey I killed my self for making such a good explanation... is it really bad?

      Comment


      • #4
        Heh heh...not really. I'm just not into slow back-end db stuff. Did you get it fixed? There's a database forum at the link mentioned above...
        Zoobie or not Zoobie...That is the problem.
        <body onUnload="flush( ! )">

        Comment


        • #5
          Problem removing child

          Not yet, the problem is not in the database side, but in the client, when the pop up reads the hidden fields to populate it's fields, then it tries to removeChild, that's when the problem occurs, an "invalid argument" to the removeChild method.

          Comment


          • #6
            The tempObject might be null or something when you call removeChild because you reset tempChilds after removing an input. Try alerting the tempObject.
            Code:
            var tempChilds = parent.all.tags("input");
            ...
            for(idx=0;idx<lengthOfChilds;idx++)
            {
              tempObject = tempChilds[idx];
              ...
              alert(tempObject);
              parent.removeChild(tempObject);
              tempChilds = parent.all.tags("input");
              ...
            }
            Resetting the children variable after removing a child will cause some children objects to be skipped in the loop.

            I don't know if that makes sense or my observation is correct. It's hard without seeing it online.
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              I had a similar problem (I think).

              a. Original FORM A creates POP-UP 1
              b. FORM A then submits itself (POP-UP 1 still visible).
              c. New FORM A gets replaced by the server (POP-UP 1 still visible)
              d. New FORM A can't modify/close POP-UP 1

              ??

              If that's the case.

              Try adding an OnLoad to your replacement FORM A
              that opens the POP-UP again. This will give it ownership again.

              Comment


              • #8
                Try this diagnostic:
                Code:
                alert(document.body.firstChild.ownerDocument == tempObject.ownerDocument);
                What does it say - true or false?
                "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

                Comment


                • #9
                  problem removing a child

                  I'll try that and will let u know the results, I did an "alert" just before removing the field and I "did see that the hidden field I was going to removed indeed had a value, id and name, can it be possible that the popup does not "own" those fields and for some reason cannot remove them.


                  alert("this is the field to remove:"+tempObject.name+" value:"+tempObject.value+ " id:"+tempObject.id)
                  parent.removeChild(tempObject);
                  tempChilds = parent.all.tags("input");

                  The field to be removed was the one that I was expecting to remove. it has the expected name, data & id.

                  Now remember this same logic works when the popup creates the fields the first time("popup creates the fields on the main window, them the main window "post's" its form to the server....data is saved in the database, then when the users wants to edit or view it's report, the data is read from db, THE ASP CREATES THE HIDDEN FIELDS" ---- and the popup tries to delete them.....

                  I know now if this is the problem, may be that the fields "not created in the fly" cannot be removed....


                  I'll do what u suggest and 'll let u know what happens

                  Comment


                  • #10
                    problem removing childs

                    Hey my friend I did that "alert" and it's true
                    --- after some time I'm getting back to this problem

                    thanks

                    Comment


                    • #11
                      the link is wrong it has a , in the end. And helper/helper don't log you in

                      Comment


                      • #12
                        problem removing childs

                        Had to re-do the db, it's up and running, helper/helper will be the access....

                        Comment


                        • #13
                          can someone help me with the &quot;lessfields()&quot; function???

                          Code:
                          <script LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
                          var counter = 0;
                          function moreFields() 
                          {
                          	counter++;
                          	var newFields = document.getElementById('readroot').cloneNode(true);
                          	newFields.id = '';
                          	newFields.style.display = 'block';
                          	var newField = newFields.childNodes;
                          	for (var i=0;i<newField.length;i++) 
                          	{
                          		var theName = newField[i].name
                          			if (theName)
                          				newField[i].name = theName + counter;
                          	}
                          	var insertHere = document.getElementById('writeroot');
                          	insertHere.parentNode.insertBefore(newFields,insertHere);
                          	alert("inside var = " + counter);
                          	return counter;
                          }
                          function lessFields()
                          {
                          	var elementnaam = 'track' + counter;
                          	document.getElementById("track" +counter).parentNode.parentNode.removeChild(document.getElementById("track" +counter).parentNode);
                          	counter--;
                          	return counter;	
                          }
                          
                          window.onload = moreFields;
                          </script>
                          
                          <div id="readroot" style="display: none"><input type="textfield" size="5" name="track"></div>
                          
                          <input type="textfield" size="5" name="track">
                          </div>
                          <form>
                          <select name='genre_id'>
                          <option value='1'>Rock</option>
                          <option value='2'>Blues</option>
                          </select>
                          Select genre<br>
                          <select name='artist_id'>
                          <option value='1'>'68 Comeback</option>
                          <option value='2'>Ace, Johnny</option>
                          <option value='3'>Adams, Art</option>
                          <option value='4'>Alabama Slammers, the</option>
                          <option value='5'>etc</option>
                          </select>select Artist or insert one <a href=''>here</a><br>
                          <input type="text" size="3" name="album_naam" value="">album Name<br>
                          <input type="text" size="3" name="album_jaar" value="">Album Year<br>
                          <textarea name="album_info" rows="3" cols="20"></textarea>Album Information<br>
                          <input type="text" size="3" name="album_medium_info" value="">Album Medium<br>
                          <span id="writeroot"></span>Track Name<br>
                          <input type="button" onClick="javascript:moreFields();alert('outside var = ' + counter);" value="Additional track" />
                          <input type="button" value="Remove track" onclick="javascript:lessFields();" />
                          
                          </form>

                          I can't get the remove function to work, it is supposed to remove the last added line, can someone please assist??

                          Comment

                          Working...
                          X