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!"); 
        if (document.all){ //input.name doesn't work in IE 
            input = document.createElement('<input name="field_'+ctr+'"> x <input name="field_'+ctr+'">'); 
            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+". ")); 
        var row = document.createElement('tr'); 
        window.document.the_form.count.value = ctr; 

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"> 
              <td height="30"> 
                1. <input name="marquee_1" type="text" class="textfield" id="field_1" /> 
              <td height="30"> 
                2. <input name="marquee_2" type="text" class="textfield" id="field_2" /> 
              <td height="30"> 
                3. <input name="marquee_3" type="text" class="textfield" id="field_3" /> 
          <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. :)

8 Years
Discussion Span
Last Post by emhmk1

It has to be a problem with your php script which parses the information from the form. I have run your form and it works fine for me, and I also created some php code for the variables you post from the form and it all works fine and dandy for me. Maybe you should check your php variables if they are getting the form values correctly. Sometimes we send "post" from the html form and we execute "$_GET" on php by mistake. Also check your functions etc. Make sure your PHP code is not only correct in itself but also that it works as it should according to what your form says.


Thanks for your reply violarisgeorge,

As it turns out it did work fine in Mozilla but not in IE, i shoulda tested it further really! However a simple fix in the script sorted it.
all i needed was to change this line

input = document.createElement('<input name="field_'+ctr+'"> x <input name="field_'+ctr+'">');

to this

input = document.createElement('<input name="marquee_'+ctr+'"> x <input name="marquee_'+ctr+'">');

Thanks again!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.