MayoorPatel
asked on
Dynamic form fields added with appendChild or innerHTML do not POST on submit
Hi there I have the following code which you can paste directly into a file and test.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="styles/screen.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/Jscript.js"></scri pt>
<script type="text/javascript">
function formvalidation(thisform)
{
with (thisform)
{
var where_to= confirm("All Form Changes You've Made Will Now Be Saved.");
if (where_to== true)
{
thisform.action = 'PPForm_3.asp?Action=Next' ;
thisform.project.submit();
}
}
}
function addEvent(eventtype)
{
var ni = document.getElementById("m yDiv"+even ttype);
var numi = document.getElementById('t heValue');
var num = (document.getElementById(" theValue") .value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('di v');
newdiv.setAttribute("id",d ivIdName);
if (eventtype == 'link')
{
newdiv.innerHTML = "<input type=\"file\" name="+eventtype+num+" /> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+ divIdName+ "\',\'" + eventtype + "\')\">Remove";
}
else
{
newdiv.innerHTML = "<input type=\"text\" name="+eventtype+num+" /> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+ divIdName+ "\',\'" + eventtype + "\')\">Remove";
}
ni.appendChild(newdiv);
}
function removeEvent(divNum,eventty pe)
{
var d = document.getElementById("m yDiv"+even ttype);
var olddiv = document.getElementById(di vNum);
d.removeChild(olddiv);
}
</script>
</head>
<form
name="project"
method="post"
class="cmxform"
onsubmit="return formvalidation(this);"
enctype="multipart/form-da ta" >
<input type="hidden" name="ID" value="<%=Request.QueryStr ing("ID") %>">
<!-- #include file="includes/header.asp" -->
<tr>
<td height="943"></td>
<td valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="3">
<tr>
<td width="16" height="14"></td>
<td width="786"></td>
</tr>
<tr>
<td height="444"></td>
<td valign="top">
<table width="544" border="0" cellpadding="2" cellspacing="3">
<tr>
<td>Related Links</td>
<td colspan="2">
<label>
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onclick="addEvent('link'); ">+ Add Some Related links +</a></p>
<div id="myDivlink"> </div>
</label>
</td>
</tr>
<tr>
<td>Related URL's</td>
<td colspan="2">
<label>
<input type="hidden" value="0" id="Hidden1" />
<p><a href="javascript:;" onclick="addEvent('url');" >+ Add Some Related URL's +</a></p>
<div id="myDivurl"> </div>
</label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td align="right"><input type='submit' value='Next >>'></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="485"></td>
<td> </td>
</tr>
<!--DWLayoutTable-->
</table>
</td>
<td></td>
</tr>
</form>
</table>
</body>
</html>
I can seem to get the form variables to post anything. The form submit is multipart enctype as the dynamic elements are "file" types.
Can Anyone Help?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="styles/screen.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/Jscript.js"></scri
<script type="text/javascript">
function formvalidation(thisform)
{
with (thisform)
{
var where_to= confirm("All Form Changes You've Made Will Now Be Saved.");
if (where_to== true)
{
thisform.action = 'PPForm_3.asp?Action=Next'
thisform.project.submit();
}
}
}
function addEvent(eventtype)
{
var ni = document.getElementById("m
var numi = document.getElementById('t
var num = (document.getElementById("
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('di
newdiv.setAttribute("id",d
if (eventtype == 'link')
{
newdiv.innerHTML = "<input type=\"file\" name="+eventtype+num+" /> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+
}
else
{
newdiv.innerHTML = "<input type=\"text\" name="+eventtype+num+" /> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+
}
ni.appendChild(newdiv);
}
function removeEvent(divNum,eventty
{
var d = document.getElementById("m
var olddiv = document.getElementById(di
d.removeChild(olddiv);
}
</script>
</head>
<form
name="project"
method="post"
class="cmxform"
onsubmit="return formvalidation(this);"
enctype="multipart/form-da
<input type="hidden" name="ID" value="<%=Request.QueryStr
<!-- #include file="includes/header.asp"
<tr>
<td height="943"></td>
<td valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="3">
<tr>
<td width="16" height="14"></td>
<td width="786"></td>
</tr>
<tr>
<td height="444"></td>
<td valign="top">
<table width="544" border="0" cellpadding="2" cellspacing="3">
<tr>
<td>Related Links</td>
<td colspan="2">
<label>
<input type="hidden" value="0" id="theValue" />
<p><a href="javascript:;" onclick="addEvent('link');
<div id="myDivlink"> </div>
</label>
</td>
</tr>
<tr>
<td>Related URL's</td>
<td colspan="2">
<label>
<input type="hidden" value="0" id="Hidden1" />
<p><a href="javascript:;" onclick="addEvent('url');"
<div id="myDivurl"> </div>
</label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td align="right"><input type='submit' value='Next >>'></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="485"></td>
<td> </td>
</tr>
<!--DWLayoutTable-->
</table>
</td>
<td></td>
</tr>
</form>
</table>
</body>
</html>
I can seem to get the form variables to post anything. The form submit is multipart enctype as the dynamic elements are "file" types.
Can Anyone Help?
ASKER
here you go!
// JScript File
function openpopup(popurl){
var winpops=window.open(popurl ,"","width =500,heigh t=150,resi zable")
}
function getClient() {
if (window.frames.length==0) return ""; // no iframes here
var ifr = window.frames['ifrClient'] ;
if (!ifr) return ""; // no iframe called ifrClient here
var sel = ifr.document.getElementsBy Name('Clie ntID')[0]
return sel.options[sel.selectedIn dex].value
}
function getContact() {
if (window.frames.length==0) return ""; // no iframes here
var ifr = window.frames['ifrContact' ];
if (!ifr) return ""; // no iframe called ifrClient here
var sel = ifr.document.getElementsBy Name('Cont actID')[0]
return sel.options[sel.selectedIn dex].value
}
function getDesignPhase() {
if (window.frames.length==0) return ""; // no iframes here
var ifr = window.frames['ifrDesign'] ;
if (!ifr) return ""; // no iframe called ifrClient here
var sel = ifr.document.getElementsBy Name('Desi gnPhaseID' )[0]
return sel.options[sel.selectedIn dex].value
}
function valuevalidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(valu e);
if (datatype)
{smalldatatype=datatype.to LowerCase( );
if (smalldatatype.charAt(0)== "i") {checkvalue=parseInt(value )};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function digitvalidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(valu e);
if (datatype)
{smalldatatype=datatype.to LowerCase( );
if (smalldatatype.charAt(0)== "i") {checkvalue=parseInt(value ); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}} ;
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
// JScript File
function openpopup(popurl){
var winpops=window.open(popurl
}
function getClient() {
if (window.frames.length==0) return ""; // no iframes here
var ifr = window.frames['ifrClient']
if (!ifr) return ""; // no iframe called ifrClient here
var sel = ifr.document.getElementsBy
return sel.options[sel.selectedIn
}
function getContact() {
if (window.frames.length==0) return ""; // no iframes here
var ifr = window.frames['ifrContact'
if (!ifr) return ""; // no iframe called ifrClient here
var sel = ifr.document.getElementsBy
return sel.options[sel.selectedIn
}
function getDesignPhase() {
if (window.frames.length==0) return ""; // no iframes here
var ifr = window.frames['ifrDesign']
if (!ifr) return ""; // no iframe called ifrClient here
var sel = ifr.document.getElementsBy
return sel.options[sel.selectedIn
}
function valuevalidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(valu
if (datatype)
{smalldatatype=datatype.to
if (smalldatatype.charAt(0)==
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function digitvalidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(valu
if (datatype)
{smalldatatype=datatype.to
if (smalldatatype.charAt(0)==
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
Hi,
Taking a break from unpacking in new home, so really don't have much time...but this:
with (this.form)
........
thisform.project.submit();
}
seems somewhat strange to me. I'm presuming the 'thisform' is the form object. If that is the case, what is 'project'???? If the form name, it's unneeded.
(oh well, back to the boxes..... :)
Taking a break from unpacking in new home, so really don't have much time...but this:
with (this.form)
........
thisform.project.submit();
}
seems somewhat strange to me. I'm presuming the 'thisform' is the form object. If that is the case, what is 'project'???? If the form name, it's unneeded.
(oh well, back to the boxes..... :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
js/Jscript.js
too