Hi, I have several form elements that I need to hide / show on a rails form. I’m ok with that.
I also need to set some elements that are hidden on the rails form. Not so sure how to set these rails form elements in jquery (that are hidden).
How is this done?
When you say “set” do you mean change the value assigned to them? And when you say “hidden”, do you mean in the CSS sense of “display: none” or in the HTML sense of
<input type="hidden" ...>?
First, some (maybe all) browsers will not submit a value for a form input that has been hidden by CSS with
display: none. Maybe not all field types, definitely true of file inputs. It’s a security/privacy thing.
Second, that’s not true of
If you want to change the value of any form element with jQuery, you use the
val() method to do that.
$('some css to target the input').val('new value') will set the value.
That has nothing at all to do with Rails, just jQuery.
If you can show a more complete example of what you’re trying to do, I can offer additional advice.