views:

69

answers:

1

how can i express the value of a textbox in xpath ?

the text that was just typed into the textbox.

so if i type apple inside a textbox, i need to output the value of this in xpath.

A: 

First off, if you're doing this more than once or twice, the overhead of doing the xpath repeatedly is probably not desirable.

document.evaluate("id('textareaid')", document, null, XPathResult.STRING_TYPE,null).stringValue;`

will return the text from inside the textarea, but not the text input afterwards.

What you want is the value property not the value attribute. xpath can only see the attribute, not the property.

So... to get the value of the textarea input, you need:

var mytextarea = document.evaluate("id('textareaid')", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;

var text = mytextarea.value;

Note: document.getElementById() is much better than an xpath that only searches by id. I assume your case is more complicated so I've left the xpath structure in place.

See https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript for more detail.

Jonathan Fingland
so how to get the value property ?
asdfasdf
See the second block of code. `mytextarea.value` is the value property. `mytextarea.getAttribute('value')` would be the value attribute. You want the property.
Jonathan Fingland