Lautarox Posted January 8, 2009 Share Posted January 8, 2009 I have this php code with a form.. <?php echo'<html> <head> <script type="text/javascript" src="addform.js"></script> </head> <body>'; $album = $_GET['a']; $date = time(); $dia = date("j", $date); $mes = date("n", $date); $year = date("Y", $date); echo ' <table border=0> <div id="readroot" style="display: none"> <input type="hidden" name="album" value="'.$album.'"> <tr> <td><input type="button" value="Eliminar Ultima" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"></td> </tr><tr> <td>Album ID: '.$album.'</td> </tr><tr> <td>Fecha:</td> <td><select name="day">'; for($i=1;$i<=31;$i++) { if($i == $dia) { echo '<option value="'.$i.'" selected="selected">'.$i.'</option>'; } else { echo '<option value="'.$i.'">'.$i.'</option>'; } } echo'</select>'; echo'<select name="month">'; for($i=1;$i<=12;$i++) { if($i == $mes) { echo '<option value="'.$i.'" selected="selected">'.$i.'</option>'; } else { echo '<option value="'.$i.'">'.$i.'</option>'; } } echo '</select>'; echo '<select name="year">'; for($i=$year;$i>$year-6;$i--) { if($i==$year) { echo '<option value="'.$i.'" selected="selected">'.$i.'</option>'; } else { echo '<option value="'.$i.'">'.$i.'</option>'; } } echo '</select> </td> </tr><tr> <td>Comentario o texto Adicional</tr> </tr><tr> <td><textarea rows="5" cols="26" name="text" maxlenght="250"></textarea></td> </tr> </div> <form name="photos" method="post" action="?go=10&d="> <span id="writeroot"></span> <tr> <input type="hidden" name="ammount" value="1"> <td><input type="button" id="moreFields" onclick="moreFields();" value="Mas Fotos"></td> <td><input type="submit" value="Subir Fotos"></td> </tr> </table> </form>'; echo' </body></html>'; ob_end_flush(); ?> And I have a javascript function to duplicate the form, I don't know really why isn't working, at the begining It wasn't even showing the form, so I added an ob_end_flush(), and now it adds the form, but incorrectly, not as the javascript function does. var counter = 0; function moreFields() { counter++; var newFields = document.getElementById('readroot').cloneNode(true); newFields.id = ''; newFields.style.display = 'block'; var newField = newFields.childNodes; for (var i=0;i<newField.length;i++) { var theName = newField[i].name if (theName) newField[i].name = theName + counter; } var insertHere = document.getElementById('writeroot'); insertHere.parentNode.insertBefore(newFields,insertHere); document.photos.ammount.value = counter; } window.onload = moreFields; Any suggestions? This is what's printing <div id="readroot" style="display: none;"> </div><div id="" style="display: block;"> -> it creates the div and it closes it </div><span id="writeroot"></span> -> it was supposed to write all the parts of the form before writeroot but instead it's only writing the div ¬¬ <table border="0"> <input name="album" value="12" type="hidden"> <tbody><tr> <td><input value="Eliminar Ultima" onclick="this.parentNode.parentNode.removeChild(this.parentNode);" type="button"></td> </tr><tr> <td>Album ID: 12</td> </tr><tr> <td>Fecha:</td> <td><select name="day">*select omitted * </select> </td> </tr><tr> <td>Comentario o texto Adicional</td></tr> <tr> <td><textarea rows="5" cols="26" name="text" maxlenght="250"></textarea></td> </tr> <form name="photos" method="post" action="?go=10&d="></form> <tr> <input name="ammount" value="1" type="hidden"> <td><input id="moreFields" onclick="moreFields();" value="Mas Fotos" type="button"></td> <td><input value="Subir Fotos" type="submit"></td> </tr> </tbody></table> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 1, 2009 Share Posted March 1, 2009 Fixed it up for you: var counter = 0; function moreFields() { counter++; var newFields = document.getElementById('readroot').cloneNode(true); newFields.id = ''; newFields.style.display = 'block'; var newField = newFields.childNodes; for (var i=0;i<newField.length;i++) { var theName = newField[i].name; if (theName){ newField[i].name = theName + counter;} } var insertHere = document.getElementById('writeroot'); insertHere.parentNode.insertBefore(newFields,insertHere); document.photos.ammount.value = counter; } window.onload = moreFields; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.