hance2105 Posted June 25, 2013 Share Posted June 25, 2013 hello guys, i have a table where product name, product brand and product description is stored. i managed to make a chained drop down with product name and product brand. i need help to display the product description based on the selection of the second drop down. in my table the product name can be the same but brands are different and for each brand there is a product description. it is that product description that i need to display. any help please? Link to comment https://forums.phpfreaks.com/topic/279562-how-to-populate-a-text-area-based-on-the-option-selected-in-second-drop-down/ Share on other sites More sharing options...
Psycho Posted June 25, 2013 Share Posted June 25, 2013 You haven't provided enough information. You've posted this in the PHP forum, so either you want the user to make the selection and then submit the page to populate the textarea or you want to do it dynamically and have posted in the wrong forum (should be in JavaScript). Assuming you want it to be static, create an onchange trigger for the second select list. That trigger should call a function that will take the ID of the selected record and make an AJAX call to a page that will take that ID and get the description of the selected product. Alternatively, if you don't have a very large number of products, you can get the descriptions for all the products and create a JavaScript array. Then reference that array whenever the option is changed in the select list to populate the relevant description. This will provide better performance since you won't have to do a call to the server. Link to comment https://forums.phpfreaks.com/topic/279562-how-to-populate-a-text-area-based-on-the-option-selected-in-second-drop-down/#findComment-1437837 Share on other sites More sharing options...
hance2105 Posted June 25, 2013 Author Share Posted June 25, 2013 well i want the description to be displayed in the text area when the option in the second drop down is selected can't that be done in php? if not, can you tell me a forum where i might get an answer for it? Link to comment https://forums.phpfreaks.com/topic/279562-how-to-populate-a-text-area-based-on-the-option-selected-in-second-drop-down/#findComment-1437841 Share on other sites More sharing options...
Irate Posted June 25, 2013 Share Posted June 25, 2013 It can be done with PHP if you force the user to submit after he selected an option. PHP is used to produce what I call "semi-dynamic" pages, dynamic in the sense that each user can see a different page, but is not forced to, and semi because it does not produce actual dynamic effects on the client. As Psycho said, dynamic client side effects (what you are trying to produce) are best done with JavaScript. If you know PHP, you will not have that much of a problem with learning JavaScript, syntax is pretty similar (besides from a few differences in variable declaring, calling methods of an object and string concatenation, but that's all minor). Link to comment https://forums.phpfreaks.com/topic/279562-how-to-populate-a-text-area-based-on-the-option-selected-in-second-drop-down/#findComment-1437844 Share on other sites More sharing options...
Psycho Posted June 25, 2013 Share Posted June 25, 2013 well i want the description to be displayed in the text area when the option in the second drop down is selected can't that be done in php? if not, can you tell me a forum where i might get an answer for it? I already stated that you should post in the JavaScript forum (on this site). What you apparently want to implement is AJAX - which is a combination of JavaScript and a server-side process (such as PHP). I already explained the basic process you would probably want to follow in the 2nd paragraph of my first response. Here's the thing, it is not "difficult" but it requires the person implementing it to be familiar with JavaScript, PHP and how to make them work together. If you don't have that basic knowledge, trying to teach you will not be a trivial task. So, the only other option is for us to write it for you. Link to comment https://forums.phpfreaks.com/topic/279562-how-to-populate-a-text-area-based-on-the-option-selected-in-second-drop-down/#findComment-1437870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.