I have a form with several fields and I need to customize some fields using javascript for allow me to:
-
prefill the value “New York” for the field “city”
-
make the field “email” readonly
-
prefill AND make readonly the field “country”
To get the result of point 1, I used this code which works well:
<script type="text/javascript">function on_form_loaded(event) {
if (event=='reserve')
document.getElementById('city').setAttribute("value", "New York");
}</script>
For get the result of point 2, I used this code which works well:
<script type="text/javascript">function on_form_loaded(event) {
if (event=='reserve')
document.getElementById('email').readOnly=true;
}</script>
But now I don’t see how to “mix” prefill/readonly paramters for get the result of point 3.
Someone can help ?
In addition I would like shorten the code for avoid to include a single javascript for each field. I make some test but without success. if you can give me some example…
I’m not sure what you’re missing but try this
As jimjimmy1985 mentioned in the comments above, you can also do this in markup