Learning JS.. so bare with me.
When I call my function in tag in the HTML body it works without any issue, but if I try to put the data in an external .js file to keep the body clean (practicing for longer functions and functions commonly used) it does not function
Example HTML file snippet of the data:
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script type="text/javascript" src="login.js"></script>
</head>
<body>
<table>
<tbody>
<tr>
<td><label for="email">Email:</label></td>
<td><input type="email" name="email" id="email"></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="password" id="password"></td>
</tr>
</tbody>
</table>
<button type="button" onClick="getLoginValue();">Submit</button>
</body>
</html>
Example JS file
getLoginValue()
{
var enteredPassword = document.getElementById("password").value;
var enteredEmail = document.getElementById("email").value;
alert(enteredEmail+' '+enteredPassword);
}
Example of HTML file that works:
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script type="text/javascript" src="login.js"></script>
</head>
<body>
<table>
<tbody>
<tr>
<td><label for="email">Email:</label></td>
<td><input type="email" name="email" id="email"></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="password" id="password"></td>
</tr>
</tbody>
</table>
<button type="button" onClick="getLoginValue();">Submit</button>
<script>
function getLoginValue(){
var enteredPassword = document.getElementById("password").value;
var enteredEmail = document.getElementById("email").value;
alert(enteredEmail+' '+enteredPassword);
}
</script>
</body>
</html>