<!-- JavaScript:DOM code snippet 8. -->
<!-- Reference and gain access to login form field values with dot and array notation:
read user name, hidden and password fields from a login form. -->
<!-- Proof that password is not encrypted when in the password field of the form. -->

<!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" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
/* accessing form elements, controls or fields */
function retrieveValues()
{
	/* declare a variable and assign to the first form */
	var e = document.forms[0]
	/* declare an array of undetermined size to store the values */
	var valueArray = new Array()
	/* loop through the form fields assigning the values to the array */
	for(var i=0; i<e.elements.length; i=i+1)
	{
	valueArray[i] = e.elements[i].value
	}
		/* loop through the array to access the stored values */
		for (var j=0; j<valueArray.length; j=j+1)
		{
    	window.alert("The values in this form are: "+valueArray[j])
		}
}
//]]>
</script>
</head>

<body>
<!-- this is the first form in the document -->
<form name="frmLogin" id="frmLogin">
<p>User name:</p><input type="text" name="userName" size="50" /><br />
<input type="hidden" name="hiddenValue" value="hiddenFieldValue" />
<p>Password:</p><input type="password" name="password" size="50" />
</form>
<br />

<!-- this is the second form in the document -->
<form name="retrieveForm" id="retrieveForm">
<!-- calls function when button is clicked -->
<input type="button" value="Access this login form's values" onclick="retrieveValues()" />
</form>

</body>
</html>