cancer10
09-18-2009, 05:28 PM
Hi
I am trying to populate new FILE elements on the fly using javascript. I am able to do it but I cannot retrieve the attachment file names when I click on submit. Can you please help me with this?
Thanks
<html>
<head>
<script>
function addElement()
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('file');
var divIdName = 'my'+num+'Div';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = '<input name="name" type="file" id=""/>';
ni.appendChild(newdiv);
}
</script>
</head>
<body>
<?php
if($_POST['submit']=='submit'){
foreach($_FILES['name'] as $x){
echo $x . '<BR>';
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onClick="addElement();">Add Some Elements</a></p>
<div id="myDiv"><input name="name" type="file" id=""/> </div>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
I am trying to populate new FILE elements on the fly using javascript. I am able to do it but I cannot retrieve the attachment file names when I click on submit. Can you please help me with this?
Thanks
<html>
<head>
<script>
function addElement()
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('file');
var divIdName = 'my'+num+'Div';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = '<input name="name" type="file" id=""/>';
ni.appendChild(newdiv);
}
</script>
</head>
<body>
<?php
if($_POST['submit']=='submit'){
foreach($_FILES['name'] as $x){
echo $x . '<BR>';
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onClick="addElement();">Add Some Elements</a></p>
<div id="myDiv"><input name="name" type="file" id=""/> </div>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>