Det eneste forskellige vi skriver, er måden at få det netop indsatte id ud af mysql db'en.
Prøv at lege lidt med det her:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd"> <html><head><title>X antal formfelter</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
body {
background-color: white;
color: black;
font-size: 0.8em;
font-family: verdana, arial, sans-serif;
margin: 20px;
}
.textinput {
font-size: 0.9em;
background-color: #FFFFFF;
color: #000000;
border-width: 1px;
border-color: black;
}
.submit {
font-size: 0.9em;
background-color: #E9E9E9;
color: #000000;
border-width: 1px;
border-color: black;
}
.submitknap {
padding-left: 60px;
}
</style>
<script type="text/javascript">
function form_fields($antal) {
if(er_et_tal($antal) != false && $antal > 0) {
var ialt = 0;
var upref = document.getElementById("formfelter");
while (upref.firstChild) {
upref.removeChild(upref.firstChild);
}
while(ialt < $antal) {
newDiv=document.createElement("div");
newDiv.style.padding = "2px";
upref.appendChild(newDiv);
try {
newElement=document.createElement("<input type='text' name='nytfelt[]' class='textinput'>");
} catch (e) {
newElement=document.createElement("input");
newElement.setAttribute("name", "nytfelt[]");
newElement.setAttribute("type", "text");
newElement.setAttribute("class", "textinput");
}
upref.appendChild(newElement);
ialt++;
}
}
}
function er_et_tal() {
var reg = /^[\d]+$/;
var navn = document.getElementById("antalfelter");
if(navn.value !='' && !navn.value.match(reg)){
alert("Kun tal kan indtastes i feltet!");
var val = new String(navn.value);
navn.value = val.substring(0,(val.length-1));
return false;
}
}
</script>
</head>
<body>
<form name="form_post" action="" method="post">
Antal viste felter: <input type="text" name="antal" onkeyup="er_et_tal();" size="2" id="antalfelter" class="textinput">
<input type="button" value="Vis felter" class="submit" onclick="form_fields(this.form.antal.value);" onkeydown="form_fields(this.form.antal.value);">
<div id="formfelter" style="padding: 16px;">
<script type="text/javascript">
form_fields(3);
</script>
</div>
<br />
<div class="submitknap">
<input type="submit" value="Submit form" class="submit">
</div>
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>
</body></html>