Two problems. Firstly, that line should be:
Code:
var pp = document.getElementById("pform").getAttribute("name");
... and secondly the JavaScript should be after the declaration of the element you are looking for so that it is not executed until the document has finished loading. Also it helps debugging if you print out the value of the variable you have recovered.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="pform" id="pform">
<input type="text" name="name" id="uniqueID" value=""/>
<input type="submit" value="submit" />
</form>
<script type="text/javascript">
var pp = document.getElementById("pform").getAttribute("name");
for(i=0;i<10;i++)
{
document.write("Hello World "+pp+"<br>");
}
</script>
</body>
</html>
Bookmarks