Jump to content

CurtHolland

New Members
  • Posts

    2
  • Joined

  • Last visited

CurtHolland's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. A very nice solution. Thank You
  2. Hello, I can use the following to dynamically add fields one at a time. I need a way for the "onclick" to provide multiple dynamic fields. e.g.(first,middle,last) if(isset($_POST['submit'])){ $children = ""; $more = TRUE; $i = 1; while($more){ if((isset($_POST['child_'.$i])) && ($_POST['child_'.$i] != "")){ $children .= $_POST['child_'.$i]; $children .= "</br>"; }else{ $more = FALSE; } $i++; } mysqli_query($con, "INSERT INTO content ( `children`) VALUES ( '$children')"); } ?> <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="css/style.css"> <script type="text/javascript" src="js/fields.js"></script> <title>Add/Remove Form Fields</title> </head> <body> <div id="container"> <form action="index.php" method="post"> Children <div id="children"> <input type="text" name="child_1" placeholder="Child's Name" style="width:250px; margin-left:7px; margin-right:4px;"> <input type="text" name="title_1" placeholder="Title" style="width:250px; margin-left:7px; margin-right:4px;"> <input type="button" id="add_field()" onClick="addField()" value="+"> </div> <input type="submit" name="submit" value="Submit"> </form> </div> </body> </html> SCRIPT var i = 1; function addField(){ i++; var div = document.createElement('div'); div.innerHTML = "<input type='text' name='child_"+i+"' style='width:250px; margin-left:7px; margin-right:7px;'><input type='button' id='add_field()' onClick='addField()' value='+'><input type='button' onClick='removeField(this)' value='-'>"; document.getElementById('children').appendChild(div); } function removeField(div){ document.getElementById('children').removeChild(div.parentNode); i--; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.