Gender checkbox data is not storing properly in local storage except 'MALE' checkbox, only 'MALE' checkbox is working 'FEMALE' and "OTHERS' are not working.
form page for taking input and saving it into local storage using javascript.
form.html
<!DOCTYPE html>
<html>
<head>
<title>FORM</title>
<script>
function getdata(){
var name = document.getElementById("name").value;
var mob = document.getElementById("mob").value;
var email = document.getElementById("email").value;
localStorage.setItem("txtValue", name);
localStorage.setItem("txtValue_2" ,mob);
localStorage.setItem("txtValue_3", email);
var male = document.getElementById("male");
var female = document.getElementById("femlae");
var others = document.getElementById("others");
if(male.checked==true){
localStorage.setItem("txtValue_1", "MALE");
}else if(female.checked==true){
localStorage.setItem("txtValue_1", "FEMALE");
}else if(others.checked==true){
localStorage.setItem("txtValue_1", "OTHERS");
}else{
localStorage.setItem("txtValue_1", "ERROR");
}
}
function remove(){
window.localStorage.clear();
}
</script>
</head>
<body align="center" onload="remove()">
<h1>FORM</h1><br>
<form action="display.html" method="get">
NAME : <input type="text" name="name" id="name"><br>
GENDER : male <input type="radio" name="male" id="male">
female <input type="radio" name="female" id="female">
others <input type="radio" name="others" id="others"><br>
Mobile No. : <input type="text" name="mob" id="mob"><br>
Email : <input type="email" name="email" id="email"><br>
<br><br>
<button type="submit" onclick="getdata()" onclick="gender()">SUBMIT</button>
</form>
</body>
</html>
display page for accessing local storage and displaying it.
display.html
<!DOCTYPE html>
<html>
<head>
<title>display</title>
<script>
function display(){
document.getElementById("data").innerHTML=localStorage.getItem("txtValue");
document.getElementById("data1").innerHTML=localStorage.getItem("txtValue_1");
document.getElementById("data2").innerHTML=localStorage.getItem("txtValue_2");
document.getElementById("data3").innerHTML=localStorage.getItem("txtValue_3");
}
</script>
</head>
<body onload="display()" align="center">
NAME : <span id="data"></span><br>
GENDER : <span id="data1"></span><br>
MOBILE NO. : <span id="data2"></span><br>
EMAIL : <span id="data3"></span>
</body>
</html>