nelliott10 0 Newbie Poster

By using the code seen below I am trying to produce a dynamic form. When the user selects an item for the product drop down menu I would like the product's barcode number to appear in the barcode box, I have been informed that this can be done using Javascript, however, I have never used this before.

I am also unsure on how to code the PHP insert command for this form which will insert all of this information into my back-end mySQL database, please not that addshopfloorcount.php as seen in the code below does not currently exist.

<form method="post" action="../php/addshopfloorcount.php">

The code for the whole form can be seen below. Any help which can be given will be much appreciated.

<form method="post" action="../php/addshopfloorcount.php">
          <table id="count" width="80%" border="1" class="table_text">
			  <tr>
			    <td colspan="4" class="table_text">Count Information:</td>
			  </tr>
			  <tr>
			    <td width="20%" align="center" >Count ID</td>
			    <td width="40%" align="center" >Department</td>
			    <td width="40%" align="center" >Username</td>
			  </tr>
		  <tr>
		    <td colspan="-3" align="center"><input name="id" type="text" id="id" size="10" maxlength="10" /></td>
		    <td align="center"><select name="department" id="department">
              <option value="--- Select Department ---">--- Select Department ---</option>
              <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from department order by id asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
              <option value="<? echo $row_list['id']; ?>" <? if($row_list['id']==$select){ echo "selected"; } ?>><? echo $row_list['department']; ?> </option>
              <?
					// End while loop.
					}
				  ?>
            </select>            </td>
		    <td align="center"><select name="username" id="username">
              <option value="--- Select Username ---">--- Select Username ---</option>
              <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from members order by id asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
              <option value="<? echo $row_list['id']; ?>" <? if($row_list['id']==$select){ echo "selected"; } ?>><? echo $row_list['username']; ?> </option>
              <?
					// End while loop.
					}
				  ?>
            </select>            </td>
		    </tr>
		    </table>

          <table id="lines" width="80%" border="1" class="table_text">
            <tr>
              <td colspan="5" class="table_text">Product Information:</td>
            </tr>
            <tr>
              <td width="10%" align="left">&nbsp;</td>
              <td width="30%" align="left">Barcode</td>
              <td width="30%" align="left" >Product</td>
              <td width="30%" align="left" >Quantity</td>
            </tr>
            <tr>
              <td align="right"><input type="checkbox" name="chk" id="chk" /></td>
              <td colspan="-3" align="center"><input name="barcode" type="text" id="barcode" readonly="readonly" /></td>
              <td align="left">
              <select name="product" id="product" onchange='javascript:document.getElementByID("barcode").value=this.value;'>
                <option value="--- Select Department ---">--- Select Product ---</option>
                <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from `lines` order by barcode asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
                <option value="<? echo $row_list['barcode']; ?>" <? if($row_list['barcode']==$select){ echo "selected"; } ?>><? echo $row_list['product']; ?> </option>
                <?
					// End while loop.
					}
				  ?>
              </select></td>
              <td><input type="text" name="quantity" id="quantity" /></td>
            </tr>
            <tr>
              <td align="right"><input type="checkbox" name="chk" id="chk" /></td>
              <td colspan="-3" align="center"><input name="barcode1" type="text" id="barcode1" readonly="readonly" /></td>
              <td align="left"><select name="product1" id="product1">
                <option value="--- Select Department ---">--- Select Product ---</option>
                <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from `lines` order by barcode asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
                <option value="<? echo $row_list['barcode']; ?>" <? if($row_list['barcode']==$select){ echo "selected"; } ?>><? echo $row_list['product']; ?> </option>
                <?
					// End while loop.
					}
				  ?>
              </select></td>
              <td align="left"><input type="text" name="quantity1" id="quantity1" /></td>
            </tr>
            <tr>
              <td align="right"><input type="checkbox" name="chk" id="chk" /></td>
              <td colspan="-3" align="center"><input name="barcode2" type="text" id="barcode2" readonly="readonly" /></td>
              <td align="left"><select name="product2" id="product2">
                <option value="--- Select Department ---">--- Select Product ---</option>
                <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from `lines` order by barcode asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
                <option value="<? echo $row_list['barcode']; ?>" <? if($row_list['barcode']==$select){ echo "selected"; } ?>><? echo $row_list['product']; ?> </option>
                <?
					// End while loop.
					}
				  ?>
              </select></td>
              <td align="left"><input type="text" name="quantity2" id="quantity2" /></td>
            </tr>
            <tr>
              <td align="right"><input type="checkbox" name="chk" id="chk" /></td>
              <td colspan="-3" align="center"><input name="barcode3" type="text" id="barcode3" readonly="readonly" /></td>
              <td align="left"><select name="product3" id="product3">
                <option value="--- Select Department ---">--- Select Product ---</option>
                <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from `lines` order by barcode asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
                <option value="<? echo $row_list['barcode']; ?>" <? if($row_list['barcode']==$select){ echo "selected"; } ?>><? echo $row_list['product']; ?> </option>
                <?
					// End while loop.
					}
				  ?>
              </select></td>
              <td align="left"><input type="text" name="quantity3" id="quantity3" /></td>
            </tr>
            <tr>
              <td align="right"><input type="checkbox" name="chk" id="chk" /></td>
              <td colspan="-3" align="center"><input name="barcode4" type="text" id="barcode4" readonly="readonly" /></td>
              <td align="left"><select name="product4" id="product4">
                <option value="--- Select Department ---">--- Select Product ---</option>
                <?
					// Get records from database (table "name_list").
					$list=mysql_query("select * from `lines` order by barcode asc");
		
					// Show records by while loop.
					while($row_list=mysql_fetch_assoc($list)){
				  ?>
                <option value="<? echo $row_list['barcode']; ?>" <? if($row_list['barcode']==$select){ echo "selected"; } ?>><? echo $row_list['product']; ?> </option>
                <?
					// End while loop.
					}
				  ?>
              </select></td>
              <td align="left"><input type="text" name="quantity4" id="quantity4" /></td>
            </tr>
          </table>
          
		  <table width="50%" border="0">
			  <tr>
			    <td><input type="button" value="Add Row" onclick="addRowToTable();" /></td>
			    <td><input type="button" value="Remove Row" onclick="removeRowFromTable();" /></td>
			    <td><input type="submit" name="save_count" id="save_count" value="Save Count" /></td>
			  </tr>
		  </table>
                 
          </form>