开发者

form not identifying the new input fields generated through a javascript

I am developing a site in php.

i have some issues with my form

i have to more than one software packages at a time.

so i have used javascript to append file and a dropdown to my html.

i have called ajs function to add开发者_开发知识库 the new input fields each time when i click a link.

and its displaying correctly.

but its not identifying in my action page.

i cant take the value of new input fields which i have created through that javascript function.

below is the code page which i have used.

<script language="JavaScript">

function addInput(divName){

  var newsel= document.createElement('div');
         newsel.innerHTML="<div style='padding-left:55px;padding-top:10px';>Operating System: <select name='frm_os1' id='test1' ><option value=''>--Select OS--</option><optgroup label='Spind Enabled'> </optgroup><option value='bc_linux'>&nbsp;&nbsp;&nbsp;bc_linux</option><optgroup label='Packages'> </optgroup><option value='Linux'>&nbsp;&nbsp;&nbsp;Linux</option><option value='Solaris'>&nbsp;&nbsp;&nbsp;Solaris</option><option value='2000/XP/Vista'>&nbsp;&nbsp;&nbsp;2000/XP/Vista</option><option value='XP/Vista'>&nbsp;&nbsp;&nbsp;XP/Vista</option><option value='2K/XP/Vista/W7'>&nbsp;&nbsp;&nbsp;2K/XP/Vista/W7</option><option value='HP'>&nbsp;&nbsp;&nbsp;HP</option><option value='Windows 2000/XP/Vista zip'>&nbsp;&nbsp;&nbsp;Windows 2000/XP/Vista zip</option><option value='Windows 2000/XP/Vista exe'>&nbsp;&nbsp;&nbsp;Windows 2000/XP/Vista exe</option><option value='X Server - 2.2M'>&nbsp;&nbsp;&nbsp;X Server - 2.2M</option><option value='Fonts - 32.9M'>&nbsp;&nbsp;&nbsp;Fonts - 32.9M</option></select></div>";
         document.getElementById(divName).appendChild(newsel);

          var newdiv = document.createElement('div');
          newdiv.innerHTML = "<div style='padding-left:40px;padding-top:10px';>Upload Software File: <input type='file' name='frm_image1' class='text_area'></div>";
          document.getElementById(divName).appendChild(newdiv);

}



</script>
</HEAD>

                                          <form action="act-add-software.php" method="post" onSubmit="return validate(this);" enctype="multipart/form-data">




                                                  <select name="frm_os"  class="text_area" style="width:200px">
                                                        <option value="">--Select OS--</option>
                                                            <optgroup label="Spind Enabled"> </optgroup>
                                                            <option value="bc_linux">&nbsp;&nbsp;&nbsp;bc_linux</option>
                                                            <optgroup label="Packages"> </optgroup>
                                                            <option value="Linux">&nbsp;&nbsp;&nbsp;Linux</option>
                                                            <option value="Solaris">&nbsp;&nbsp;&nbsp;Solaris</option>
                                                            <option value="2000/XP/Vista">&nbsp;&nbsp;&nbsp;2000/XP/Vista</option>
                                                            <option value="XP/Vista">&nbsp;&nbsp;&nbsp;XP/Vista</option>                                                            
                                                            <option value="2K/XP/Vista/W7">&nbsp;&nbsp;&nbsp;2K/XP/Vista/W7</option>                                                            
                                                            <option value="HP">&nbsp;&nbsp;&nbsp;HP</option>                                                            
                                                            <option value="Windows 2000/XP/Vista zip">&nbsp;&nbsp;&nbsp;Windows 2000/XP/Vista zip</option>                                                          
                                                            <option value="Windows 2000/XP/Vista exe">&nbsp;&nbsp;&nbsp;Windows 2000/XP/Vista exe</option>
                                                            <option value="X Server - 2.2M">&nbsp;&nbsp;&nbsp;X Server - 2.2M</option>
                                                            <option value="Fonts - 32.9M">&nbsp;&nbsp;&nbsp;Fonts - 32.9M</option>                                                                                                                                                                                  
                                                            </select>
                                                            <a onClick="addInput('dynamicInput');">Add More Package</a> </td>
                                                  </td>
                                                </tr>
                                                <tr>
                                                  <td colspan="2"><table border="0" cellpadding="0" cellspacing="0">
                                                      <tr align="center" valign="middle" class="tbl_row1">

                                                        <td height="25" align="left" class="font1" width="156" bgcolor="White"><div align="right">
                                                            <?if(strstr($frm_server_side_error,'frm_software')){?>
                                                            <font class="error"><b> <font color="#dd0000">*</font>&nbsp;Upload Software File: </font>
                                                            <?}else{?>
                                                            <font class="form_element"> <font color="#dd0000">*</font>&nbsp;Upload Software File:
                                                            <?}?>
                                                          </div>
                                                          </B> </td>

                                                        <td  class="font1"  bgcolor="White" align="center" style="padding-left:2px;"><input type="file" name="frm_image[]" class="text_area">
                                                        </td>
                                                        <?if($frm_sfile !=""){?>
                                                        <td  class="font1"  bgcolor="White" align="center"></td>
                                                        <?}else{?>
                                                        <td  class="font1"  bgcolor="White" align="center">&nbsp;(Current File: NOT Uploaded Yet) </td>
                                                        <?}?>
                                                      </tr>
                                                    </table></td>
                                                </tr>

                                                <tr>
                                                <td colspan="2">
                                                <div id="dynamicInput">
                                                </div>
                                                </td>
                                                </tr>

                                          </form>

For the simplicity of viewing this code page i have included only required code lines

please help me to solve this issue


This would be because <input type='file' name='frm_image1' class='text_area'> uses an static name.

So each call to addInput() nicely creates all the elements, all sharing the same name.

To easily solve this you could append an iterator to the name and store it in the global scope.

var iterator=0;

function addInput(){
    var name = 'inputElementName'+(iterator++);
    // etc...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜