I have two datasets in JSON (data.json) as shown below:
UP = [{"password": "jhonjhon", "username":"jhon"}, {"password": "juliejulie", "username":"julie"}, {"password": "blakeblake", "username":"blake"}];
AND
Admins = '[{"Admin":"jhon"}, {"Admin":"julie"}]';
I have an HTML form that the user will use to login.
<html> <body> <form name="myForm" onsubmit="finalCheck()"> UserName<input type="text" id="uid" value="UserId"/> UserPassword<input type="password" id="pwd" value="UserPwd"/> <input type="submit"/> </form> </body> <script src="data.json"></script> <script src="checking.js"></script> </html>
When I click the Submit button, I want to first check whether the entered username (stored in var, say x
) was in the Admins
list in my JSON file or not, For example: if x
is jhon
I want to know if the same exists jhon
in Admins
JSON .
JavaScript at the moment:
function finalcheck(){ var x = document.forms["myForm"]["uid"].value; var y = document.forms["myForm"]["pwd"].value; }
Help with JavaScript is much appreciated!
source share