This is a JAVASCRIPT assignment. I do not need a bunch of CSS stuff to make it p
ID: 3684903 • Letter: T
Question
This is a JAVASCRIPT assignment. I do not need a bunch of CSS stuff to make it pretty, I just want the mechanics to work as noted. Create a login form that prompts for a user name and password. Include a checkbox that when checked will save the user name in a cookie and if the user returns to the login form and a cookie is set, default the user name to the cookie value. I will reiterate, I need two PROMPTS, one for user name and one for password. I need a checkbox that stores the user name in a cookie when checked. This all needs to be in a FORM.
The second page that I need is also a JAVASCRIPT assignment. Create a form that prompts for a first name, last name and email address. When the user submits the form, save the values entered using cookies and then forward to a second web page that will read the cookies and display the stored information. Again, it needs to save the entered information from the PROMPTS and sends them to a second web page that reads and displays the information from the cookies.
I downvote for incorrect answers, or if I feel you didn't read the whole thing.
Explanation / Answer
Prog-1
<html>
<title>
Sample cookie-Login
</title>
<head>
<script>
function login()
{
if(document.getElementById('uname').value="")
{
var uname=prompt("Enter username");
document.getElementById('uname').value=uname;
}
var pwd=prompt("Enter pwd");
document.getElementById('pwd').value=pwd;
readCookie('uname');
}
function saveData()
{
if(document.getElementById('save').checked)
setCookie('uname',document.getElementById('uname').value);
}
function setCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0)
{
document.getElementById(name).value=c.substring
(nameEQ.length,c.length);
}
}
return null;
}
</script>
</head>
<body> <form>
<table>
<tr><td>Username
<td><input id=uname></tr>
<tr><td>Password
<td><input id=pwd></tr>
<tr><td colspan=2>
<input type=checkbox id=save>Remember Me?</tr>
<tr><td colspan=2 align=center>
<input type=button value=Submit></tr>
</table>
</form>
</body>
</html>
Prog-2
<html>
<title>
Sample cookie-Personal Info
</title>
<head>
<script>
function takeAction()
{
if(document.getElementById('fname').value="")
{
var fname=prompt("Enter first name");
document.getElementById('fname').value=fname;
}
if(document.getElementById('lname').value="")
{
var lname=prompt("Enter last name");
document.getElementById('lname').value=lname;
}
if(document.getElementById('email').value="")
{
var email=prompt("Enter email id");
document.getElementById('email').value=email;
}
readCookie('fname');
readCookie('lname');
readCookie('email');
}
function saveData()
{
setCookie('fname',document.getElementById('fname').value);
setCookie('lname',document.getElementById('lname').value);
setCookie('email',document.getElementById('email').value);
}
function setCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0)
{
document.getElementById(name).value=c.substring
(nameEQ.length,c.length);
}
}
return null;
}
</script>
</head>
<body> <form>
<table>
<tr><td>First Name:
<td><input id=fname></tr>
<tr><td>Last Name:
<td><input id=lname></tr>
<tr><td>Email Id:
<td><input id=email></tr>
<tr><td colspan=2 align=center>
<input type=button value=Submit></tr>
</table>
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.