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? Commented 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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but i want to retrieve "Text" attribute of textbox?
For <input> and <textarea>, use .value.
@HiteshDhamat that would be .value as described in this answer. For example: document.getElementById("myTextBox").value.
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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.