• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

accessing the value in a DOM tree

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have html document. In that document I have some code that looks like the following:
<tr>
<td>Name:</td>
<td>
<div class="Data" id="login_name">
<input type=text></input>
</div>
</td>
</tr>
The user enters in their login name (and their password in another input box not shown here) and presses a button on the page that says "login". The button has onclick="login(); function. In "login()" to access what the user entered in the input box by accessing the DOM tree. Here is what I am doing right now.
// the login is actually a var that can contain the login
// name or password. This returns an object
var element = document.getElementById("login_name");
// child = INPUT, which it should
var child = element.firstChild.nodeName;
[don't know what the next line here should be]
What I am trying to do is access is the value a user types into the input box. I can look at the DOM tree and see:
+ DIV = Name IV Type:ELEMENT_NODE Att:class=Data,id=login_name
INPUT - Name:INPUT Type:ELEMENT_NODE Att: value=bob
note that the user here types bob in thee login text area. I've tried various ways to access this "bob" value but cannot find the correct method. I will need to be able to read/write this text area. Should I change my actual HTML and put XML tags around the <input type=text></input> to something like <LOGINNAME><input type=text></input></LOGINNAME> and this will create a way to access the value in the input box? Any help would be appreciated.
Thanks in advance,
Joe Crew
[ Ajith disabled smilies in the post so that the colon prefixed characters are not interpreted as UBB images ]
[This message has been edited by Ajith Kallambella (edited April 26, 2001).]
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe, it�s not completely clear where XML fits into picture. You said that you have HTML document. If so, you do not need to worry about XML at all. In this case DOM (Document Object Model) is an object model of your HTML page. If you want to read
value of text field, you can read its �value� property using JavaScript. But in this case your id should be on <input> element itself, not on <div>:
<div class="Data">
<input type=text id="login_name"></input>
Then in your login() function you can write:
login ()
{
var element = document.getElementById("login_name");
alert (element.value );
}
Does it help?
 
Joe Crew
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mapraputa,
You were 100% correct in your response. Thank you so very much. I am kind of new to this so I did kind of asked the question incorrectly. But you saw through it and gave me the correct answer anyway. You were right in that it was not XML but just a DOM tree itself, and I was just trying to access the value in an input box.
Thanks again,
Joe Crew
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe, thank you for asking!
When we approach a new field it is difficult even to formulate the problem, so do not worry about �incorrect� questions. We all learn here and �incorrectly asked� question are the most useful (at least, for those who answer ). I remember somebody here said that �ill-defined� questions are more useful than �well-defined�, because they make us actually think, instead of just rearranging words. That what I felt answering college tests - often it is possible to answer by repeating words, without understanding what I am saying - qustions are too correct!
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic