Hi,

I have a js script:

var inputCounter = 0;
function addInput(divName){	 
	var newdiv = document.createElement('div');	
	newdiv.innerHTML = "somefield1: " + "<input type='text' style='width: 250px;' name='f1[]'> somefield2: " + "<input type='text' style='width: 200px;' name='f2[]'>";
	document.getElementById(divName).appendChild(newdiv);
	inputCounter++;	

}

and the data was received by the php script

$_SESSION["f1"] = $_POST["f1"];	
$_SESSION["f2"] = $_POST["f2"];

was working perfectly, until i did some minor changes to the script that was not even related to that part of the script, and it now shows Notice: Undefined index: f1 in C:\Apache2.2\htdocs\ts\index.php on line xxx
meaning that the data is not set anymore. everything else is working perfectly. the fields are still added as before, but the data does not post. what might cause this not to work all of a sudden?

edit: just tested the page on IE and there it still works as it should. Firefox, however, gives me that error. even on different computers. now i'm confused.

Ok, i've found that i need to .createElement('input'); for each of them.

How do i do it nicely so i have a div with several different inputs like i'm having now in the innerHTML part?

And why was it working before and still is on IE?

hi. I have the same problem. But on Chrome and FF.
dynamically created elements don't get a 'name', so they are not submitted on the form $_POST.

How did you work around this issue?

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.