0

How to retrieve the text given in any field using javascript in C#?

sumry.innerHTML += "<li>" + f.getAttribute("Text") + "</li>" + "<br/>";
                        f.style.borderColor = "#FF0000";
                        f.focus();
1
  • defined "field". you mean the content of the tag or the content of the attribute?
    – iMoses
    Sep 12, 2012 at 8:49

2 Answers 2

1

You're probably looking for .nodeValue, possibly .innerHTML, possibly .value for a form field.

.getAttribute() will retrieve an attribute from a tag, such as id or name. It won't get the content of the tag.


Your current code is expecting an element formed like this:

<some_element id='blah' text='hey hey hey' />`

Of course, text is not an attribute, so there's no return value.

3
  • Thanks, but i want to retrieve "Text" attribute of textbox? Sep 12, 2012 at 8:52
  • For <input> and <textarea>, use .value.
    – Ben
    Sep 12, 2012 at 8:53
  • 1
    @HiteshDhamat that would be .value as described in this answer. For example: document.getElementById("myTextBox").value.
    – Fenton
    Sep 12, 2012 at 8:54
0

Your question is not clear.. If i got it, you want to use data from code behind in your script. The easiest way is to create a hidden field, set its value on form load, and then read it using getElementById('myhidden').value.

Best regards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.