needs_upgrade Posted July 28, 2008 Share Posted July 28, 2008 Hello guys! I need help in working javascript and php together. I have these two tables in my MySQL database: CREATE TABLE `products` ( `product_id` int(10) unsigned NOT NULL auto_increment, `product_code` varchar(10) NOT NULL, `product_name` varchar(30) NOT NULL, `selling_price` decimal(10,2) unsigned NOT NULL default '0.00', PRIMARY KEY (`product_id`) ); CREATE TABLE `purchase_details` ( `purchase_detail_id` int(15) unsigned NOT NULL auto_increment, `purchase_id` int(10) unsigned NOT NULL, `product_id` int(5) unsigned NOT NULL, `quantity` decimal(7,2) unsigned NOT NULL, `unit_price` decimal(10,3) unsigned NOT NULL default '0.000', `unit_discount` decimal(8,3) unsigned NOT NULL default '0.000', `net_price` decimal(13,3) NOT NULL, `balance` decimal(8,2) NOT NULL, PRIMARY KEY (`purchase_detail_id`) ); And in my php file named add_sale, i have this form: $show_form = "<form name='AddSaleForm' action='add_sale.php' method='post'> <table class=data border=1><thead class=data>"; $show_form .= "<tr><td align=center colspan=4><b>Product Details</b></td></tr>"; $show_form .= "<tr> <td align=center>Product Name</td> <td align=center>Selling Price</td> <td align=center>Qty Available</td> <td align=center>Qty To Be Sold</td> </tr></thead><tbody class=data>"; for ($i=1; $i<21; $i++) { $show_form .= "<tr> <td align=left><select name='product_id$i' onChange=\"Populate_selling_price_and_quantity_available()\"><option value=>Product Name</option>"; // select only the products that are non-zero in values in the inventory $sql = "SELECT p.product_id, p.product_name FROM products p, purchase_details pd WHERE pd.product_id = p.product_id AND SUM(pd.balance) > 0 ORDER BY p.product_name"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)) { show_form .= "<option value=$prow[0]>$prow[1]</option>"; } $show_form .= "</select></td> <td align=center><input readonly=1 type=text class=TextBox size=10 name='selling_price$i'></td> <td align=center><input readonly=1 type=text class=TextBox size=10 name='quantity_available$i'></td> <td align=center><input type=text class=TextBox size=3 name='quantity_2_b_sold$i' onblur=\"check_if_quantity_2_b_sold_IS_NOT_GREATER_THAN_quantity_available()\"></td> </tr>"; } $show_form .= "<tr><td align=center colspan=4> <input type=reset> <input onClick=\"EvalAddSaleForm()\" type=button value=Submit></td></tr>"; $show_form .= "</tbody></table></form>"; print $show_form; What i need is: 1. If I have selected a product in the drop down menu named product_id, the Populate_selling_price_and_quantity_available() function will a. show the selling price in the uneditable selling_price textbox and b. show the quantity available in the uneditable quantity_available textbox. // the sql for showing the quantity available: "SELECT SUM(balance) FROM purchase_details WHERE product_id = '$selected_product_id_from_drop_down_menu'"; 2. If i have entered a value in the quantity_2_b_sold textbox, the check_if_quantity_2_b_sold_IS_NOT_GREATER_THAN_quantity_available() function will automatically check that its value is not greater than the value in the uneditable selling_price textbox Thank you very much in advanced guys. More power to you all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.