Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
what i could get information from html in javascript?
for example i want get data from html in textbox of language asp.net c#


<head>
<javascript language="javascript">
/*i want get information in control by name txtdata */

</head>

<asp:textbox id="txtdata" runat="server" />
Posted

try this in Javascript
JavaScript
<html>
<head>
var textBoxvalue = document.getElementById("txtdata");
</head>
<body>
<asp:textbox id="txtdata" runat="server" xmlns:asp="#unknown" />
</body>
</body></html>
 
Share this answer
 
This is one of main purposes of JavaScript. For example, you can get an input control object using getElementById and then use its property value. In case of text input, it will be the text in the text box. Please see:
http://www.tizag.com/javascriptT/javascript-getelementbyid.php[^],
http://www.w3schools.com/tags/tag_input.asp[^].

Starting from any element, you can also get the whole DOM model of the whole document of its part. Please start here:
http://www.w3schools.com/jsref/default.asp[^],
http://www.w3schools.com/jsref/dom_obj_document.asp[^].

It's more convenient to work with HTML DOM elements using jQuery:
http://en.wikipedia.org/wiki/Jquery[^],
http://jquery.com/[^].

For example, this is the equivalent of getElementById:
JavaScript
inputElement = $("#myTextBox"); // element wrapper, found by the id selector, if the element has the attribute id="myTextBox"
value = inputElement.val(); // use this wrapper
Please see:
http://api.jquery.com/id-selector/[^],
http://api.jquery.com/category/selectors/[^],
http://api.jquery.com/val/[^].

Major DOM navigation is done using traversing methods:
http://api.jquery.com/category/traversing/[^].

If you need to learn jQuery, start here:
http://docs.jquery.com/Tutorials[^],
http://docs.jquery.com/Tutorials:How_jQuery_Works[^].

—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900