Forums

Displaying Fields from the DB based on Radio Button Selection

cre8tivemedia 03 Nov, 2018
I'm using Javascript to get the value of the "id" in the DB from the radio buttons as follows
var a = jQuery("input[name='discount']:checked").val();
document.getElementById("discount_giftcard").innerHTML = a;

var b = jQuery("input[name='portal']:checked").val();
document.getElementById("discount_portal").innerHTML = b;

My HTML has the following
<h4>Discount Gift Cards "id"</h4>
<p id="discount_giftcard"></p>
<h4>Cashback Portal "id"</h4>
<p id="discount_portal"></p>

This works great but I would like to grab other fields from the database based on the radio button selections. DB fields "introtext", "alias" and "urls" Here is a form view -



Can I do this with Javascript or do I need to have another read action to be able to get these fields?
healyhatman 04 Nov, 2018
Unless you already have that data loaded and somewhere on your form, you'll need to re-read.
cre8tivemedia 06 Nov, 2018
Can I do a single read event to get all the fields that I need from the database and then grab them based on the id value of the radio buttons?
or do I need to do separate read events for each field? I just don't know which way is a more efficient way of going about it
healyhatman 06 Nov, 2018
Just reload the fields and re-read the database, makes more sense than loading all the data every single time and trying to use JQuery to filter it out and rebuild options.
cre8tivemedia 20 Nov, 2018
Ok, I've got a read action "read_data15" producing two options for a radio group. I also set up another read action "read_data17" to list different fields from the database as you can see below.



If I were to select the "id" 9568 from the radio group in "read_data15" how can I display the corresponding "alias" that has the same "id" from the "read_data17"?

Or is there another way to get the "alias" in the first read event "read_data15"? I tried adding additional fields but I'm not sure how to do that with a radio group
healyhatman 20 Nov, 2018
Look at the dynamic dropdown demo form.
cre8tivemedia 20 Nov, 2018
I've studied the dynamic dropdown demo but I'm getting nowhere... Not sure how this is used for what I'm trying to do
healyhatman 20 Nov, 2018
The first dropdown should reload the other field, and in the reload event read the database based on {data:first_field}
healyhatman 20 Nov, 2018
Which part of the dynamic dropdown demo are you stuck on? Because it definitely sounds like what you need. You want the user to select an option, and then displays to them an entry from the database based on what they've selected.
cre8tivemedia 22 Nov, 2018
That is precisely what I'm trying to do but to a third level... I currently have a dropdown that when selected populates two different radio groups with the correct information.
The dropdown id is "storename" and in the read I am using this for the where condition -

created_by_alias:{data:storename}

This seems to work as intended

What I would like to add is when the user makes a selection from the radio groups I would like to pass the data "introtext", "alias" and various other values from the database to text fields and/or hidden fields to be used for other calculations as well as information displayed to the user.

I tried using a text field but I couldn't figure out how to pass the information so I figured I would try with another radio group since I got that to work before...

I tried adding another radio group but I can only get it to work doing a read event with the dropdown id "storename", this shows the values from both radio groups and obviously won't change when the user makes a radio selection

I would like it to pull from a selection from the radio group with the id "discount"

I tried using another read with the following but had no success -

id:{data:discount}

Here is a front end view using the data from the dropdown "storename" -
link
healyhatman 22 Nov, 2018
So when you select an option from the dropdown you want to reload a whole bunch of fields at once? That's a bit more complicated. You might have to wrap them all in a custom div with a set data-reloadurl or make your own Ajax call.
cre8tivemedia 23 Nov, 2018
Since I can get the database id from the radio group selection I would like to pull information from the database based on that id. So, when a user makes a selection I can display other details about that selection.

Here is my goal -
A user makes a selection from the dropdown (Store)
which loads radio group options (Discounted Gift Cards) and (Cashback Sites)
the user makes a selection from radio group (Discounted Gift Cards)
I would like to display the discount value which would be the "introtext" field in the database and the article title which would be the "title" field in the database as well as other fields such as the url link to the article and some other information

I have limited knowledge of what you're suggesting, is there somewhere you could point me for information on how I could go about doing this?
healyhatman 23 Nov, 2018
okay so you want multiple fields from the database displayed as the label of a radio select option?
cre8tivemedia 23 Nov, 2018
I'd rather just have certain fields from the database displayed as individual text boxes or hidden fields independent of each other. I was only using a radio select option because I couldn't figure out how to do the text field...
I'd like to be able to display some of the individual fields for the user as well as have some hidden fields that I'll use for background calculations
healyhatman 23 Nov, 2018
if you don't need to have any of data put into fields you can't have a custom html block with data-reloadurl="{url:reload event}&tvout=view" and the reload event can just output the wrapper div with your data inside it. If you need all those fields populated then sorry but you'll need the wrapper div and a series of {view:field} entries inside.
cre8tivemedia 23 Nov, 2018
I don't need the fields populated until the user makes a selection from the radio group. Then, based on the database "id" of the selection I would show the specific fields from the database. Here is an example I mocked up -






So does that mean I make an html block and put this in it - data-reloadurl="{url:reload event}&tvout=view" then put a reload event in the radio group?

or am I supposed to do something like this in the html -

<div id="wrapper">
{view:}id:{data:discount}
{view:}title:{data:discount}
{view:}introtext:{data:discount}
{view:}id:{data:portal}
{view:}title:{data:portal}
{view:}introtext:{data:portal}
</div>
healyhatman 23 Nov, 2018
Do you just need to DISPLAY those fields or do you need to send their data too
cre8tivemedia 23 Nov, 2018
Some fields I just want to display but some I want to do math with. I don't think I'll need to send them.

So if a user selects the first selection in Discounted Gift Cards radio group I would display on screen some details about the store

title - A Pea in the Pod
introtext - 25.14
id - 9538

same with second radio group

in the background (hidden fields) I'd do some math. Adding together and multiplying fields and displaying the total on screen

25.14 - introtext (Discounted Gift Cards)
+
4.0 - introtext (Cashback Portal Sites)
+
-- user input
healyhatman 23 Nov, 2018
So you can use a custom html that you target

<div id="shopinfo" data-reloadurl="{url:event name}&tvout=view"></div>

In the reload event do the read data , then a custom code block containing that wrapper div with all the information you want. Do your calculations with PHP, display the information however you want.
cre8tivemedia 23 Nov, 2018
K, I'm pretty sure I don't have the syntax right... Here is what I have -









front end view - link
healyhatman 23 Nov, 2018
Yes you have the syntax wrong.

Under your "Setup" Tab you need to create a new event, and the name of that event goes in {url:event_name}

In your custom code block instead of {view:}id{data:id} you need
ID: {var:read_data#.model.field}
And instead of select type being an array of key/value pairs it should be first found, matching the thing they selected from the radio.
cre8tivemedia 26 Nov, 2018
Ok, I added a new event and updated the custom code and changed the Read to First Matching. Seems to be working ok but only if I point the Where Condition in the Read to the dropdown which is this -
created_by_alias:{data:storename}
That grabs the first of all the radio group options.

The dropdown selection fills in the radio groups and I'd like to get the info from the radio groups, I thought the syntax in the Read event Where Condition would be this -
id:{data:portal}
I think... But I don't know how to reload the read event after I've made a selection from the radio group so the custom code block stays blank

Front end link showing the read pointing to the dropdown - link
healyhatman 26 Nov, 2018
Wrll that second radio also needs an onchange event
cre8tivemedia 26 Nov, 2018
where do I put the Wrll? in the Where Event like this
id:{Wr||data:portal}
I do have an onchange event in both radio groups set to
read_data17
but I have a feeling that's not correct
I have the radio groups reading from read_data9 & read_data15
with a Where condition -
created_by_alias:{data:storename}
healyhatman 27 Nov, 2018
*well. Typo, and also not something you should be putting in like you have.

The onchange event should be set to the name of your event, not the name of an action. There should be one event for each thing so one for when the user selects the first option to reload the radios and one for when they select a radio to show the information.

You should look closer at the dynamic dropdown demo it shows all these concepts fairly clearly.
cre8tivemedia 27 Nov, 2018
I have a basic understanding of how the dynamic dropdown works but am still relatively new to Chronoforms. I know I'm close to what I need but I have something wrong somewhere and I keep trying different things but I have no idea if I'm changing the correct thing or if I have a simple typo somewhere.

I keep looking at the demo and I seem to understand it, I've got a dropdown that when selected populates the radio groups correctly. I just don't know how to join the information from the radio group selection with the read event to display the info from the database
I'm not sure what the event is, the custom code or the event loader or something else. For all I know I'm making changes to something that is already correct and just going further down a wormhole....
healyhatman 27 Nov, 2018
Well what is the value you're using for the radio? Use whatever you need to search the database when they select an option.
cre8tivemedia 27 Nov, 2018
"id" is the value of one of the radio groups (name and id set as "portal") so I was trying to do a new read event with this in the Where Condition -
id:{data:portal}
but I can't seem to figure out how to display it. I got it working correctly if I do the custom code pointing at the first level dropdown but that isn't the solution I need...
healyhatman 27 Nov, 2018
Screnshot of the events tab for that radio thanks.

At some point you might have to just consider paying me to do it for you seem to be going in circles.
This topic is locked and no more replies can be posted.