Multiple serials with multiple parts attached to it.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #61
    Obviously, that's not enough. It has to be an adequate replacement. The first line gets an element, so the replacement must do the same. So construct the string as I explained earlier and then pass it to document.getEle mentById().

    Comment

    • bonneylake
      Contributor
      • Aug 2008
      • 769

      #62
      Originally posted by acoder
      Obviously, that's not enough. It has to be an adequate replacement. The first line gets an element, so the replacement must do the same. So construct the string as I explained earlier and then pass it to document.getEle mentById().
      Hey Acoder,

      I am sorry i am still very confused. Are you saying to do something like

      Code:
      var replacevalue= document.getElementById(serialno);
      and then do the below?

      Code:
      var serialno = partName.replace("dynamic","").replace("Input","");
      an then do i need to take out the below from the parts function?

      Code:
      var avalue = document.getElementById('aValue');
      Thank you,
      Rach

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #63
        You can keep the line and just change the "aValue" string which needs to be the ID of the new element, "partscount"+se rialno.

        Comment

        • bonneylake
          Contributor
          • Aug 2008
          • 769

          #64
          Originally posted by acoder
          You can keep the line and just change the "aValue" string which needs to be the ID of the new element, "partscount"+se rialno.
          Hey Acoder,

          So the line should be this correct?

          Code:
          var avalue = document.getElementById('partc');
          an then do you want me to do the other 2 parts i mentioned above this line the ones about the serialno?

          Thank you,
          Rach

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #65
            No, this should be in addpartInput() and not set to "partc" which, if I'm not mistaken, probably doesn't exist. It should literally be set to "partscount"+se rialno.

            Comment

            • bonneylake
              Contributor
              • Aug 2008
              • 769

              #66
              Originally posted by acoder
              No, this should be in addpartInput() and not set to "partc" which, if I'm not mistaken, probably doesn't exist. It should literally be set to "partscount"+se rialno.
              Hey Acoder,

              well i think i have it all wrong so i going to show you what i got because i think i got it all upside down. Here is what i have for both functions.


              Code:
              <!---serial function --->
              function addInput(divName){
              var dynamic = document.getElementById('dynamicInput');
              var thevalue = document.getElementById('theValue');
              var count = (document.getElementById('theValue').value -1)+ 2;
              thevalue.value = count;
              var newdiv = document.createElement('div');
              var getparts = document.createElement('div');
              var divIdName = 'dynamic'+count+'Input';
              var partc = 'partscount'+count;
              
              newdiv.setAttribute('id',divIdName);
              Code:
              <!---parts function --->
              function addpartInput(partName){
              var parts = document.getElementById(partName);
              var getparts = document.getElementById('div');
              var avalue = document.getElementById('aValue');
              var avalue = document.getElementById('"partscount"+serialno');
              var count = (document.getElementById('aValue').value -1)+ 2;
              avalue.value = count;
              var partdiv = document.createElement('div');
              var partIdName = 'part'+count+'Name';
              var serialno = partName.replace("dynamic","").replace("Input","");
              
              partdiv.setAttribute('id',partIdName);
              Thank you,
              Rach

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #67
                If you put "partscount"+se rialno in quotes, then it'll be treated as a string whcih is what you don't want. On top of that, if you're setting serialno afterwards (on line 11), it won't be available on line 6. Line 5 wouldn't be needed any longer. On line 7, you're not making use of the avalue variable which you should be in place of document.getEle mentById("aValu e").

                I think either I'm not explaining well or you haven't understood what I've been trying to say. The idea was simple: change the ID to the new hidden element(s) instead of the old one.

                Comment

                • bonneylake
                  Contributor
                  • Aug 2008
                  • 769

                  #68
                  Hey Acoder,

                  Your explaining good i am just not understanding. Mostly getting confused because there is 2 of them an so its hard to keep them straight. Also, i am not best at the terminology of JavaScript so i often get thrown off by the word string or variable. although i have read up on JavaScript and looked at examples and understood what i read and the examples, its hard for me to apply it to what i am working on. An i also been sick last few days so i haven't been able to fully focus either. So your doing a good job :), just me being slow which i am sorry i am being slow on this. But anyway i understood everything except the part about line 7 does the aValue that appear in this line
                  Code:
                  var count = (document.getElementById('aValue').value -1)+ 2;
                  need to be changed to

                  Code:
                  var count = (document.getElementById('avalue').value -1)+ 2;
                  Here is the parts function with everything else added

                  Code:
                  <!---parts function--->
                  function addpartInput(partName){
                  var parts = document.getElementById(partName);
                  var getparts = document.getElementById('div');
                  var avalue = document.getElementById("partscount"+serialno);
                  var serialno = partName.replace("dynamic","").replace("Input","");
                  var count = (document.getElementById('aValue').value -1)+ 2;
                  avalue.value = count;
                  var partdiv = document.createElement('div');
                  var partIdName = 'part'+count+'Name';
                  
                  partdiv.setAttribute('id',partIdName);
                  Thank you,
                  Rach

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #69
                    Almost there. Lines 5 and 6 need to be swapped around otherwise serialno won't be set when you use it (resulting in an error). Secondly, you need to replace the document.getEle mentById() on line 7 to this new variable (which would be set to an element) to make use of it.

                    Comment

                    • bonneylake
                      Contributor
                      • Aug 2008
                      • 769

                      #70
                      Originally posted by acoder
                      Almost there. Lines 5 and 6 need to be swapped around otherwise serialno won't be set when you use it (resulting in an error). Secondly, you need to replace the document.getEle mentById() on line 7 to this new variable (which would be set to an element) to make use of it.
                      Hey Acoder,

                      here is what i got. I think i might of done the part about line 7 wrong does it need to be set to avalue or to serialno?
                      Code:
                      <!---parts function--->
                      function addpartInput(partName){
                      var parts = document.getElementById(partName);
                      var getparts = document.getElementById('div');
                      var serialno = partName.replace("dynamic","").replace("Input","");
                      var avalue = document.getElementById("partscount"+serialno);
                      var count = (document.getElementById('avalue').value -1)+ 2;
                      avalue.value = count;
                      var partdiv = document.createElement('div');
                      var partIdName = 'part'+count+'Name';
                      
                      partdiv.setAttribute('id',partIdName);
                      Thank you,
                      Rach

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #71
                        avalue is already an element, not a string, so document.getEle mentById() is not required in that line.

                        Comment

                        • bonneylake
                          Contributor
                          • Aug 2008
                          • 769

                          #72
                          Originally posted by acoder
                          avalue is already an element, not a string, so document.getEle mentById() is not required in that line.
                          Hey Acoder,

                          So leave line 7 like this

                          Code:
                          var count = (value -1)+ 2;
                          Thank you,
                          Rach

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #73
                            I'd personally use something like:
                            Code:
                            var count = parseInt(avalue.value) + 1;

                            Comment

                            • bonneylake
                              Contributor
                              • Aug 2008
                              • 769

                              #74
                              Originally posted by acoder
                              I'd personally use something like:
                              Code:
                              var count = parseInt(avalue.value) + 1;
                              Hey Acoder,

                              Here is what i have

                              Code:
                              <!---parts function --->
                              function addpartInput(partName){
                              var parts = document.getElementById(partName);
                              var getparts = document.getElementById('div');
                              var serialno = partName.replace("dynamic","").replace("Input","");
                              var avalue = document.getElementById("partscount"+serialno);
                              var count = parseInt(avalue.value) + 1;
                              avalue.value = count;
                              var partdiv = document.createElement('div');
                              var partIdName = 'part'+count+'Name';
                              
                              
                              partdiv.setAttribute('id',partIdName);
                              an i tested out an its numbering correctly (serial information 1 parts 1 parts 2, serial information 2 parts 1 parts 2) an i only see one problem. its a hard one to explain. But basically if i add 2 parts under each serial (an i add 2 serials) . if i go to delete them all except 1 i am having the problem of it puts parts under the last serial.

                              example

                              serial information 1
                              test 1 (parts)
                              test2 (parts)

                              serial information 2
                              test 3 (parts)
                              test 4 (parts)

                              if i delete all except test 2. Instead of it remaining under serial information 1 it appears under serial information 2. Basically instead of the part remaining under the serial i added it with, its putting it under a different serial once i remove a part i added. An it happens with any part i add. Any ideas?

                              Thank you,
                              Rach

                              Comment

                              • acoder
                                Recognized Expert MVP
                                • Nov 2006
                                • 16032

                                #75
                                It seems the part div ID is not unique. Try adding the serial no. to it to make it unique, e.g.
                                Code:
                                var partIdName = 'part' + count + 'Name' + serialno;

                                Comment

                                Working...