It is still very difficult to tell what you're asking. If you post lots of code, please direct out attention to a specific line of code in that block of code that you're asking about.
My wild guess for what's going on is that when you create text nodes in this block of code:
var pTextBudget, pTextBrand, pTextType, pTextLens;
pTextBudget = document.createTextNode("Your DSLR budget range selected was: " + budText);
//linebreak.appendChild(pTextBudget);
pTextBrand = document.createTextNode("The DSLR brand you selected was: " + brandText);
//linebreak.appendChild(pTextBrand);
pTextType = document.createTextNode("The type of photography you selected was: " + typeText);
//linebreak.appendChild(pTextType);
pTextLens = document.createTextNode("The type of lenses you selected was: " + lensText);
//linebreak.appendChild(pTextLens);
// append text to paragraph
pNodeBudget.appendChild(pTextBudget);
pNodeBrand.appendChild(pTextBrand);
pNodeType.appendChild(pTextType);
pNodeLens.appendChild(pTextLens);
// remove pNodes and append changes again
You are assigning the text nodes to local variables. Those variables ONLY exist for the during of this function. They will not retain their values until the next time you call this function. If you need them to retain their values, then you should declare those variables as global variables (outside the function) and NOT declare them inside the function at all.
In other words, if you want the variables to retain their values, then move this line:
var pTextBudget, pTextBrand, pTextType, pTextLens;
to outside of the onChange()
function so the variables are defined in a scope that survives from one call to your function to the next. Local variables (variables declared with var
inside a function) ONLY exist for the duration of that one invocation of the function. After the function finishes, those variables are destroyed and the next time the function is called, new ones are created.
Now all that said, there is almost never a good reason to store DOM references to text nodes in global variables. You generally locate text nodes inside of <span>
or <div>
elements that contain ids or class names and you use DOM queries to find a given node when you need it. Code tends to be a lot, lot cleaner when written that way. I really have no idea what the point of your code is without spending hours trying to understand it so I can't recommend a specific way for you to rewrite/restructure your code to work this better way.