I'm trying to set a field in a list's edit form with a value after the user clicks "Save." Here's the catch: I don't want the field to be editable by the user (only JavaScript should set its value).
So first, I tried setting the field's "readonly" attribute. Didn't work - after saving the form, I find out that the value didn't take. So I think, "maybe SharePoint ignores saving read-only fields." Instead, I add styling to set its "display" to "none." I find out that this gives the same result as above.
I also tried adding a span, setting its positioning to "absolute", and giving it a solid background color, and increasing the z index so that it would cover up the field. No luck - still didn't save the value when I clicked "Save."
I even tried overriding the "PreSaveAction" function to make the field visible afterwards, but that didn't work either.
Unfortunately, it seems the only way for this to work is to allow the field to be completely visible and completely editable by the user, for the entire lifespan of the page, because when I tried that, it worked fine.
Is there something I'm missing?
EDIT: I forgot to mention that this list has a 2010 workflow that runs when an item is edited.
.attr('disabled', 'disabled')
. It works for me.