I am currently producing a system in which I want the user to be able to select the product name from a drop-down menu and when selected I would like the barcode to appear in the barcode field. I would really appreciate any help, however great or small.

The current code which I have for this is: -

<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" value="<?php ?>" readonly="readonly" /></td>
              <td align="left"><select name="product" id="product">
                <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>

add some thing (given below) to you dropdown code

"><select name="product" id="product" onchange='javascript:document.getElementByID("barcode").value=this.value;'>

I have implemented the code as suggested by urtrivedi however, it is still not working. Any ideas as to why?

Member Avatar for diafol

This implementation depends upon the nature of your data. Do you want the barcode data to be retreived from the DB / files in a folder / a javascript array on new selection (onchange)?

If from DB - use ajax
If from files or js - just use js - no need for ajax.

You can load data to the dropdown on creation via php:

$output = "<select name=\"bcode\" id=\"bcode\" onchange=\"doBC();\">";
while($data = mysql_fetch_array($results)){
   $output .="<option value=\"{$data['bcodefile']}\">{$data['label']}</option>";
}
$output .= "</select>";
....

<div id="barcode_img"></div>

The doBC() js function simply gets the bcode dropdown value and then changes the div.

Hi, my name is Elliot. I just learn php, but I just have not gotten it yet.
I need help developing a form for my bee website where interested persons can join the bee club. Can anyone help? I will post the fields if I get someone to help.
Thank you.

You will need to use dynamic dropdowns with a bit of javascript for this.
you only need AJAX if you have more details for each one, or tens of thousands of barcodes.

I have created some tutorials on this at my site

Read both the tutorials on changing one select menu based on another. (the database one second)

and this is one of the more efficient ways to do this.

hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.