Click to See Complete Forum and Search --> : How can I name any html element?


said_fox
04-17-2003, 06:50 PM
Hi,
in forms, we can easly call any property for it.
e.g
suppose we have a text field, its name is mytext, belongs to a form, its name myform. So we can assign its value in JavaScript or any other property like bgcolor etc as
document.myform.mytext.value="Hi this's my value"

The question is,
How can I do some thing like this for any other html tag, like table or font?:confused:

pyro
04-17-2003, 07:18 PM
Well, I would recommend doing it with either <div>'s or <span>'s but you can give them an ID and call them by that. Take a look at this example:

<html>
<head>
<script language="javascript" type="text/javascript">
function getText()
{
currentText = document.getElementById("mydiv").innerHTML;
alert (currentText);
}
</script>
</head>
<body onload="getText()">
<div id="mydiv">This is a test</div>
</body>
</html>