Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:43:47+00:00 2026-05-28T20:43:47+00:00

Given HTML like this: <body> <form name=myForm action=savedata.php method=post> <input type=text name=myName /> </form>

  • 0

Given HTML like this:

<body>
<form name="myForm" action="savedata.php" method="post">
  <input type="text" name="myName" />
</form>
</body>

Using document.getElementById, I would acces the input calledmyName` like this:

var getName = document.getElementById('myName').value;

But, instead, I know I can do this, and I like it better:

var getName = document.myForm.myName.value;

Does this second method have a way? And, is it ok to use myForm.myName or should I use getElementById?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:43:47+00:00Added an answer on May 28, 2026 at 8:43 pm

    First off, your first bit of “DOM” code is wrong. getElementById('myName'); isn’t going to get the element you want, since it has no id – just a name attribute. Similarly, I don’t believe your tree-navigating second bit of code will work since elements are stored by id, not by name.

    Now, dismissing that, both examples you posted are “DOM”. You have a document which is structured as a tree of node objects. You’re navigating it as such. The former snippet (were it to be written correctly) is just a more standard means of access.

    As for what you should do (I’m assuming from the tags you’re asking about JavaScript code in particular): either way works. The first idea (insofar as it uses getElementById) is better because a change in your document structure won’t break it, but if it’s you who’ll be mopping up the broken glass, it’s all your show.

    To illustrate my point, let’s say you put the input element in a div. Code using getElementById would still work. Code navigating the tree downward would not, since it doesn’t have a property-get to go through the new intervening element. Thus, you’ve coupled your logic to your display – and that’s a code smell.

    Take a look at jQuery if you don’t already know about it; it, and similar libraries, make JavaScript a much more pleasant language in which to develop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In form.php <html> <body> <form action=process.php method=post> <input type=text name=dat /> <input type=submit value=submit
I have a webpage that looks like: <html> <head> <title>Hi</title> </head> <body> <form name=mainForm
Given this HTML: <div>foo</div><div>bar</div><div>baz</div> How do you make them display inline like this: foo
Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html
I have a html string like this: <html><body><p>foo <a href='http://www.example.com'>bar</a> baz</p></body></html> I wish to
I'm trying to select an element given by: /html/body[@id='someid']/form[@id='formid']/div[@id='someid2']/div[@id='']/div[@id='']/div[@id='']/table/tbody[@id='tableid']/tr[7]/td[2] Now the html of that
Similar to this question, my HTML looks like this: <body id=body onload=loader()> </body> I
Given an HTML link like <a href=urltxt class=someclass close=true>texttxt</a> how can I isolate the
Given an HTML string like: <span class=findme id=31313131313>The Goods</span> What kind of REGEX in
Basically, I would like to decode a given HTML document, and replace all special

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.