Jump to content

How to populate a text area based on the option selected in second drop down


hance2105
Go to solution Solved by Psycho,

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.