Link to home
Start Free TrialLog in
Avatar of MayoorPatel
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"></script>

<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("myDiv"+eventtype);
        var numi = document.getElementById('theValue');
        var num = (document.getElementById("theValue").value -1)+ 2;
        numi.value = num;
        var divIdName = "my"+num+"Div";
        var newdiv = document.createElement('div');
        newdiv.setAttribute("id",divIdName);  
        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,eventtype)
        {
        var d = document.getElementById("myDiv"+eventtype);
        var olddiv = document.getElementById(divNum);
        d.removeChild(olddiv);
        }
           
</script>

</head>

<form
    name="project"
    method="post"        
    class="cmxform"
    onsubmit="return formvalidation(this);"
    enctype="multipart/form-data" >
    <input type="hidden" name="ID" value="<%=Request.QueryString("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>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="right"><input type='submit' value='Next >>'></td>
               
              </tr>
            </table>

            </td>
        </tr>
      <tr>
        <td height="485"></td>
        <td>&nbsp;</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?
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

We need
js/Jscript.js
too
Avatar of MayoorPatel
MayoorPatel

ASKER

here you go!

// JScript File

function openpopup(popurl){
var winpops=window.open(popurl,"","width=500,height=150,resizable")
}

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.getElementsByName('ClientID')[0]
return sel.options[sel.selectedIndex].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.getElementsByName('ContactID')[0]
return sel.options[sel.selectedIndex].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.getElementsByName('DesignPhaseID')[0]
return sel.options[sel.selectedIndex].value
}

function valuevalidation(entered, min, max, alertbox, datatype)
{      
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
  {smalldatatype=datatype.toLowerCase();
   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(value);
if (datatype)
  {smalldatatype=datatype.toLowerCase();
   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;
   
   }

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..... :)
 
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial