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().
Multiple serials with multiple parts attached to it.
Collapse
X
-
Originally posted by acoderObviously, 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().
I am sorry i am still very confused. Are you saying to do something like
Code:var replacevalue= document.getElementById(serialno);
Code:var serialno = partName.replace("dynamic","").replace("Input","");
Code:var avalue = document.getElementById('aValue');
RachComment
-
Originally posted by acoderYou can keep the line and just change the "aValue" string which needs to be the ID of the new element, "partscount"+se rialno.
So the line should be this correct?
Code:var avalue = document.getElementById('partc');
Thank you,
RachComment
-
Originally posted by acoderNo, 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.
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);
RachComment
-
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
-
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;
Code:var count = (document.getElementById('avalue').value -1)+ 2;
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);
RachComment
-
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
-
Originally posted by acoderAlmost 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.
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);
RachComment
-
Originally posted by acoderavalue is already an element, not a string, so document.getEle mentById() is not required in that line.
So leave line 7 like this
Code:var count = (value -1)+ 2;
RachComment
-
Originally posted by acoderI'd personally use something like:
Code:var count = parseInt(avalue.value) + 1;
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);
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,
RachComment
Comment