Page 1 of 1

How do I change the value of a edit field with code?

Posted: Tue Sep 03, 2024 3:58 pm
by karmacomposer
I have a form on the index.php page and have session storage enabled. I named all the form fields (id) appropriately.

On a separate page (results.php) I have a form with session storage enabled, the form fields (id) are named the same and it shows the form data perfectly.

However, I would like a drop down value to be the actual text (ie. it displays 1, but should be "Option A")
Same with radio or checkboxes. Instead of a 0 or 1, I would like it to say Yes or No (ie. it displays 0 but should be "Yes")

How do I code the form or edit field to change the result to the text value?

I hope I am explaining this well. Sorry if I am not.

Mike

Re: How do I change the value of a edit field with code?

Posted: Tue Sep 03, 2024 4:17 pm
by BaconFries
This can be done with some custom javascript/jquery or with the following Form Conditions and Calculations

Re: How do I change the value of a edit field with code?

Posted: Tue Sep 03, 2024 4:24 pm
by karmacomposer
Thank you. I see you can choose javascript on the dropdown. I am used to php, but not javascript as much. How do I reference the form field values in javascript?

Code: Select all

if (document.getElementById('age').value = 0) then age.value = "Under 35";
The above code breaks the form? Any help is appreciated. Note that I am trying to change a integer value to a string as per the drop down options.

I read the conditions page, but it does not go into changing form field values (from a number to a text string), just calculations and such. A little guidance would be appreciated.

Mike