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.
<!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
Post a Comment