Whats the effects of shortening form.elements.name to form.name?

I am working with many forms in single page but I'd prefer using short notation form.name instead of form.elements.name Is there any issues if I keep shortening?

»Javascript @alshakul



» 1 answer  » 14 views   


Add photos



Gadrawin • 1 month ago
Most times there is no problem in using shorter notation since we rarely need to change name attribute in forms. But there is a little issue if we eventually change our name attribute. The problem is that both old name and new name will still be available and may lead to confusion. Lets have an example: <form id="testform"> <input name="fname" placeholder="Name"> </form> <script> testform.fname.name = "newname"; // changed console.log(form.elements.fname); // undefined console.log(form.elements.newname); // input console.log(form.fname == form.newname); // true </script> Initially, testform.elements.fname is equal to testform.fname but after changing it to newname, testform.elements.fname becomes undefined and testform.elements.newname gives output we want. Good thing, when you compare both new name and old name, they are equal because forms allow both. »

0  Dislike  •  Reply



Back to top

[SHARE THIS POST]: The post's archived Spread it to others!

Posted under this donnektish »
This community is about sharing contents such as questions and answers discussing about Javascript and TypeScript, ES5, ES6
58 people joined this donnektish



Maintain social distancing, to avoid Covid19