I've seen about 20 or more posts on the subject, but they either don't make sense to me or are slightly different.
Ive been scratching my head on this for ages. Searching for answers provides a ton of conflicting advice but nothing I have seen yet works. Ive boiled the problem down to this simple form. If I enter data in the box and click the button the alert is always undefined. Could somebody explain why please and also how I can assign the variable properly and test by pushing it out on an alert?
Thanks in advance.
Code follows:
<html>
<head>
<script src="jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
var jsPostcode = document.getElementsByName("pcode").value;
alert(jsPostcode);
});
});
</script>
</head>
<body>
<form name="login">
<table>
<td><input style="width: 80px" name="pcode" type="text" /></td>
<td><button>OK</button></td>
</table>
</form>
</body>
</html>