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

Issues related to forms.
Post Reply
karmacomposer
 
 
Posts: 19
Joined: Thu Nov 06, 2014 6:17 pm

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

Post 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
User avatar
BaconFries
 
 
Posts: 5640
Joined: Thu Aug 16, 2007 7:32 pm

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

Post by BaconFries »

This can be done with some custom javascript/jquery or with the following Form Conditions and Calculations
karmacomposer
 
 
Posts: 19
Joined: Thu Nov 06, 2014 6:17 pm

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

Post 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
Post Reply