Forums

populate text box using result of dropdown - for a beginner

stikki 27 Dec, 2016
Hi

I am new to chronoforms and jQuery and am really struggling with what seems like should be quite simple.

I have dB read that gets data from a table that include the fields session and session_price.

The dropdown on the form is called session, and using the info in FAQs I have got it to display the contents of the session field. Now I need the textbox called sessionprice to display the value that corresponds to the session chosen.

Using info in the FAQs I can make the textbox contain the value selected in the dropdown with:code]jQuery(document).ready(function(function(jQ){
jQ('#session').change(function(){
var desc;
desc=jQ('#session').find(":selected").text();
jQ('#sessionprice').val(desc);
)}
)}[/code]
But, is there a simple way to get the value of the corresponding session_price from the array?

Many thanks for your patience

Mikki
GreyHead 27 Dec, 2016
Hi Mikki,

Please see this FAQ - note that you have to copy the HTML from your drop-down into a custom code element so that you can add the data- items

Bob
stikki 27 Dec, 2016
Bob

Thanks for the reply

I looked at that FAQ but it looked like I would need to hand code in the data attributes. I need to pull in the data from a table so that the prices and session details can be updated easily.

Do you know of a FAQ that would show me how to create the dropdown and the data attributes from values in a table?

Mikki
GreyHead 27 Dec, 2016
Answer
Hi Mikki,

You can load the data from a table and use PHP in the custom code action to build the options list; or you could use the ChronoForms drop-down element but combine the price in the option value as e.g. value='xxx#price' and then use JavaScript to extract and display the price when the drop-down changes; or . . . there are a couple of other ways to get the prices when you need them too.

How you do it is up to you.

Bob
stikki 30 Dec, 2016
Thanks Bob

PHP worked well for me 😀
This topic is locked and no more replies can be posted.