Please can someone assist me with the solution to this problem. I need to store the result of the hdvest array. What is wrong with my code.
function getval() {
var e = document.getElementsByName("investresult[]");
for(var i = 0; i < e.length; i++) {
var f = e[i];
alert(f.value);
document.getElementByName("hdinvest[i]").value = f.value;
}
}
There’s an ‘s’ missing from the second use of document.getElementsByName()
Also, to get your code formatting to work, you can either highlight it and click on the </> icon on the editor toolbar, or use three backticks ( ``` ) on the line before and the line after your code.
A NodeList (as returned by getElementsByName()) doesn’t have a value property, and assigning one won’t have any effect per se. Did you mean something like
Note that naming input elements with square brackets doesn’t have any effect on the JS, it only makes PHP recognise them as an array within the action script.
Can you do a rendered version of the resulting HTML from that? I don’t think anyone is going to try interpreting your PHP to work out what HTML comes out of it, and then has some JS applied to it.