I need to display both the username and password in alert box after submitting . I tried all the ways but still not getting.I think something is wrong with the button itself.So please let me know what corrections needs to be done.
<html>
<head>
<title>LOGIN </title>
<script type="text/javascript">
function log(user,pass){
var user=document.getElementById(user).value;
var pass=document.getElementById(pass).value;
alert("username:"+user+"passw`enter code here`ord:"+pass);
}
</script>
</head>
<body>
//taking username and password in text field
<form>
Username=<input type="text" id=user placeholder="Enter your username"/></br>
Password=<input type="text" id=pass placeholder="Enter your password"/> </br>
<input type="button" id=login value="login" onclick = "log(user,pass)"/>
</form>
</body>
</html>
You just missed a quote while passing the arguments to the function.
It should be
log('user', 'pass')
(Arguments should be passed as string)
<html>
<head>
<title>LOGIN </title>
<script type="text/javascript">
function log(user, pass) {
var user = document.getElementById(user).value;
var pass = document.getElementById(pass).value;
alert("username:" + user + " password:" + pass);
}
</script>
</head>
<body>
<form>
Username=<input type="text" id="user" placeholder="Enter your username" /></br>
Password=<input type="text" id="pass" placeholder="Enter your password" /> </br>
<input type="button" id="login" value="login" onclick="log('user', 'pass')" />
</form>
</body>
</html>