javascript - Can I assign a form to a variable? -


so if have form called myform , field called myfield, know can access field using:

document.myform.myfield.value 

is there way assign form variable like:

var f = document.myform 

so can access fields using: f.myfield.value in order save myself typing?

i tried , didn't work don't know if it's not possible or if i'm doing wrong.

yes.

<!doctype html> <html> <head> <meta charset=utf-8 /> <title>js bin</title> </head> <body>   <form id="example">     <input name="field" value="default value">   </form>   <script>     var frm = document.forms.example;     alert(frm.elements.field.value);   </script> </body> </html> 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -