Functions and clearing of fields dynamically.

Clear hidden form field values to prevent unwanted database submissions.

Overview

Hidden but enabled form fields can still submit their values even when not visible.
Ensure hidden fields are disabled, not just hidden, and clear their values using form events when hiding them.

Answered
ca captainh 11 Oct, 2014
I have radio buttons that disable and show a textbox on event.
Example:
On load
[ ] Option 1 [ ] Option 2

when i click option 2
[ ] Option 1 [ X ] Option 2
Textbox 1: [ ]

when i click option 1
[ X ] Option 1 [ ] Option 2
the textbox is disabled and hidden.

My problem is that when the user types something into a textbox and that textbox becomes disabled, the value is still sent to my database on submission. Is there a way i can clear this textbox value dynamically when Option 1 is selected? The things i can think would be to use the Events and run a function when option 1 is selected. But what is it that points to this textfield box?
Gr GreyHead 13 Oct, 2014
Hi captainh,

Please double-check that the hidden text-boxes are disabled as a disabled element shouldn't Submit anything at all. (a readonly one will).

I generally also clear any elements when I hide them just to avoid old input data being inadvertently used in the wrong place.

Bob
ca captainh 13 Oct, 2014
http://i.imgur.com/IDTJVcu.png

As seen from this image. When i enter select others and locations appears and when i enter a value into it and select another value, the location box disppears. When i press submit, the location value is also submitted. As seen from my events image, i have it set on disabled when another value is selected.

Also, "I generally also clear any elements when I hide them..." How do i do this?

Thank you!
ca captainh 20 Oct, 2014
Answer
1 Likes
Fix: My form has nested textboxes that appears and disappears. So i have forgotten to disable the location textbox when another root value is selected. This has since been fixed.
This topic is locked and no more replies can be posted.