Tuesday 15 January 2013

php - how to set textbox value from sql database on changing combo box option? -


I am doing this school project which worsens me a lot of time (it seems very easy) .. then this deal is I need to set the price of a text box based on the selection of kabobox. This is what I have so far received

   Read (choose 'From Supplier'); ? & Gt; & Lt; Form action = "" method = "post" & gt; & Lt; Div align = "center" & gt; & Lt; Table & gt; & Lt; TR & gt; & Lt; Td colspan = "3" & gt; & Amp; Nbsp; & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td colspan = "3" & gt; Supplier Information & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Supplier & lt; / Td> & Lt; TD & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt; Select style = "width: 100%" id = 'slcSupplier' name = "slcSupplier" & gt; & Lt ;? Php foreach ($ result as missing $ line) {? & Gt; & Lt; Option value = "& lt ;? php echo ($ row-> supplier id) ;;>" & Gt; & Lt ;? Php echo ($ row-> supplier id. ':'. $ Line- & gt; name) ;? & Gt; & Lt; / Options & gt; & Lt ;? Php}? & Gt; & Lt; / Select & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Address & lt; / TD & gt; & Lt; TD & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt; Textarea id = "txtAddress" name = "txtAddress" & gt; & Lt; / Textarea & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; & Lt; / Form & gt;   

I need to get the address of the supplier selected from the database database and without showing the whole page is to show it on the text area. Thank you for helping ..

I resumed my code by reading HV reply

   Read (choose 'From Supplier'); ? & Gt; & Lt; Script & gt; $ (Document) .ready (function (e) {$ ("# slcSupplier"). Change (function () {var id = $ (this) .val (); $ .ajax ({url: 'supplier.php' , Method: 'post', data: "id =" + id, success: function (data) {$ ('# txtAddress'). Html (data);}});});}); & Lt; / Script & gt; & Lt; Div & gt; & Lt; Table & gt; & Lt; TR & gt; & Lt; Td colspan = "3" & gt; & Lt; Input type = "button" name = "A" id = "A" value = "submit" /> & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td colspan = "3" & gt; Supplier Information & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Supplier & lt; / Td> & Lt; TD & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt; Select style = "width: 100%" id = 'slcSupplier' name = "slcSupplier" & gt; & Lt ;? Php foreach ($ result as missing $ line) {? & Gt; & Lt; Option value = "& lt ;? php echo ($ row-> supplier id) ;;>" & Gt; & Lt ;? Php echo ($ row-> supplier id. ':'. $ Line- & gt; name) ;? & Gt; & Lt; / Options & gt; & Lt ;? Php}? & Gt; & Lt; / Select & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Address & lt; / TD & gt; & Lt; TD & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt; Textarea id = "txtAddress" name = "txtAddress" & gt; & Lt; / Textarea & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt;   

I do not know what is wrong, but javascript does not work .. im so messy ..

include jquery in your header

This is the following concept for creating a file called newpage.php

  $ supplier_id = $ _POST ['supplier_id']; // read the supplier id from post $ query "select bleach, supplier WHERE id = from blah." $ Supplier_id; // Prepare a query to retrieve the required field $ line = fetch_row ($ query); // Perform the query and get the result. $ Json = array ('field' = & gt; $ line ['field1'], 'field2' = & gt; $ line ['field2']); Echo json_encode ($ json); Then  
  $ (document) .ready (function () {$ ('# clcSupplier') in your current HTML page. Change (function () {var id = $ (this) .val (); $ .ajax ({url: 'newpage.php', type: 'post', data type: 'jason', data: "supplier_id =" + ID, success: work (data) {$ ('# txtAddress'). Val (data.field + data.field2);}})}}}}};    

No comments:

Post a Comment