anky4588 Posted September 15, 2012 Share Posted September 15, 2012 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 More sharing options...
birbal Posted September 15, 2012 Share Posted September 15, 2012 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 More sharing options...
anky4588 Posted September 16, 2012 Author Share Posted September 16, 2012 thank u so much,will try it and reply you back Link to comment Share on other sites More sharing options...
anky4588 Posted September 19, 2012 Author Share Posted September 19, 2012 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 More sharing options...
kanchatchai Posted September 19, 2012 Share Posted September 19, 2012 http://www.w3schools.com/php/php_ajax_livesearch.asp Link to comment Share on other sites More sharing options...
anky4588 Posted September 22, 2012 Author Share Posted September 22, 2012 i want this code in php. Link to comment Share on other sites More sharing options...
anky4588 Posted September 28, 2012 Author Share Posted September 28, 2012 now i want to insert a value through text box for the respective value of drop down list.plz help me. Link to comment Share on other sites More sharing options...
anky4588 Posted October 3, 2012 Author Share Posted October 3, 2012 IF I am selecting a vlaue in drop down list then how can I use that selected vlaue in php as we can use it in javascript? Link to comment Share on other sites More sharing options...
JamesB Posted October 3, 2012 Share Posted October 3, 2012 to get the value of the selected <option>: <select name="optionList" id="optionList" onchange="copy(this);" > function copy(select) { var value = select.options[select.selectedIndex].value; alert(value);} Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now