Jump to content

how to show drop down values in labels or text boxes


anky4588

Recommended Posts

hello everyone,I am new to the PHP platform so just needed help of yours,As I m designing a form in which I have used a drop down list,so i just wanted to know how to show the respective product name and its price in the label or text box when I am selecting respective product Id in the drop down list.

purchase.php

Link to comment
Share on other sites

you have to use javascript for that. if you have arbitrary number of items you should use ajax to get product info. if the list is short and fixed you colud populate data in JS and use it. for doing this you have to use JS DOM where you have to bound a callback function on onchange event on dropdown list.

Link to comment
Share on other sites

I jzz want that whenever I select a option in my drop down it's respective name and price is shown in my labels,I want it dynamically ie through my database,plz provide me the code,I used your opinion birbal.I am pasting my code plz see to it. <html><head> <title><center>Purchase Item</center></title> <style type="text/css">.main_box{width:600px;height:400px;border:1px solid#ccc;margin:0;padding:10px 15px;;background:#FFBF80;}.left_box{width:200px;height:25px;text-align:right;padding:0 5px 0 0;margin:5px 5px;float:left;}.seperator{width:10px;height:25px;padding:0 5px;margin:5px ;float:left;}.right_box{width:300px; height:25px; margin:5px; padding:0 5px; float:left;}.clear{clear:both;}</style><h1>PURCHASE</h1></head><body><div id="1" class="main_box"><div class="left_box"> <b> PRODUCT CODE</b></div><div class="seperator">:</div><div class="right_box"> <select name="optionList" id="optionList" onchange="copy();" ><option value="Select your Option " ></option> <option value="RAM" >PR1</option> <option value="KEYBOARD" ">PR2</pption> <option value="SPEAKER" >PR3</option> <option value="LED">PR4</option> </select> </div><div class"=clear";></div><div class="left_box"><b>PRODUCT NAME</b></div><div class="seperator">:</div><div class="right_box"> <div id="label"> <script language="javascript">function copy() { document.getElementById("label").innerHTML = document.getElementById("optionList").value}</script> </div></div><div class"=clear";></div> <div class="left_box"> <b> PRICE</b> </div> <div class="seperator">:</div> <div class="right_box"> <input type="text"/> </script> </input> </div><div class"=clear";></div> <div class="left_box"> <b> QUANTITY</b> </div> <div class="seperator">:</div> <div class="right_box"> <input type="text" id="quantity" value="" /> </div><div class"=clear";></div> <div class="left_box"><input name="submit" type="submit" value="SUBMIT"></div><div class="right_box"><div class="seperator"></div><input name="clear" type="reset" value="CLEAR"></div></div> </div> </form> </body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...