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

197 views   Javascript  2020.09.19


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?

Answers, ideas and Comments

» 1 idea

gadrawin • 1 year 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 



In order to go deep, share any relevant idea or posting solution to some questions, You have to sign in or create a new account if you don't have one. And get Donnekted(connected)




Log in now  Join the Team

This site is for sharing topics, questions, answers, experiences or other contents related to different stuffs, especially technology. For existing users, They can make any topic(post) to discuss about in hope for ideas or any result from other people from different communities. In order to get involved, Get donnekted(connected) by Joining us here!

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


86 people joined this donnektish


Maintain social distancing, to avoid Covid19