Hi Guys, a while back i was working on a components list for a marquee firm, the project was put on hold for a while but now i'm taking it up again. A while back i asked how to add extra input fields with an onClick button, this was achieved like so;
<script language="javascript" type="text/javascript">
function addField() {
var tbody = document.getElementById("tblBody");
var ctr = tbody.getElementsByTagName("input").length + 1;
var input;
if ( ctr > 10 ) {
alert ("Only Select 10 at a time please!");
}else{
if (document.all){ //input.name doesn't work in IE
input = document.createElement('<input name="field_'+ctr+'"> x <input name="field_'+ctr+'">');
}else{
input = document.createElement('input');
input.name = "marquee_"+ctr;
}
input.id = input.name;
input.type = "text";
input.value = "";
input.className = "textfield";
var cell = document.createElement('td');
cell.style.height = '30px';
cell.appendChild(document.createTextNode(ctr+". "));
cell.appendChild(input);
var row = document.createElement('tr');
row.appendChild(cell);
tbody.appendChild(row);
window.document.the_form.count.value = ctr;
}
}
</script>
And the html form is like so;
<form name="the_form" id="the_form" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody id="tblBody">
<tr>
<td height="30">
1. <input name="marquee_1" type="text" class="textfield" id="field_1" />
</td>
</tr>
<tr>
<td height="30">
2. <input name="marquee_2" type="text" class="textfield" id="field_2" />
</td>
</tr>
<tr>
<td height="30">
3. <input name="marquee_3" type="text" class="textfield" id="field_3" />
</td>
</tr>
<tbody>
</table>
<input name="count" type="hidden" id="count" value="4"/>
<input name="add" type="button" class="button" id="add" value="Add Another" onClick="addField();"/>
<input type="submit" name="submit" value="Get Components" />
The form (as you can tell) submits to it's self and the the database is accessed.
The problem is, the first three fields work fine but i can't seem to post any more after the 3rd! i even tried
<?php $one = $_POST['marquee_one']; ~ $ten = $_POST['marquee_ten'];
To see if it worked that way but it did not.
Does anyone have an idea about this?
Also when querying the db do i need to run a mysql_query for each posted item? or (like the method above do i need to run it 10 times)
Many thanks for looking. :)