Found a very useful helper in codeplex: SPUtility.js
- Set or get field values
- Make a field read only
- Hide a field from view
- No server side code to deploy!
I found it very useful. Here is my own prefered way to do:
- I put my script in .txt files and upload to a configuration library.
- Then, I create a Content Editor Web Part in each of DispForm.aspx / EditForm.aspx / NewForm.aspx.
- In the CEWP settings, set the url of my script files.
By doing so, I do not need to go edit the page each time I need to edit the script. I can just go edit the script in the library. Multiple pages that use the same script also can benefit in such way.