Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DMD3475/week-8/form2.html
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74 lines (57 sloc)
2.27 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Contact Form</title> | |
</head> | |
<body> | |
<form onsubmit="return false"; action="https://www.google.com/" class="form" > | |
<input type="text" onkeyup="formBlur(this)" id="username" placeholder="Name"> | |
<p id="p-user"></p> | |
<input type="subject" onkeyup="formBlur(this)" id="subject" placeholder="Subject"> | |
<p id="p-subject" ></p> | |
<input type="email" onkeyup="formBlur(this)" id="email" placeholder="Email"> | |
<p id="p-email" ></p> | |
<textarea id="textarea" onkeyup="formBlur(this)" rows="4" cols="40" placeholder="message" ></textarea> | |
<p id="p-textarea" ></p> | |
<button onclick="actionForm()" >Submit</button> | |
</form> | |
<script> | |
function actionForm() | |
{ | |
var username = document.getElementById('username'), | |
subject = document.getElementById('subject'), | |
email = document.getElementById('email'), | |
textarea = document.getElementById('textarea'); | |
if(username.value == "") | |
{ | |
document.getElementById('p-user').textContent = "* Please input your name"; | |
document.getElementById('username').style.border = "1px solid red"; | |
} | |
if(subject.value == "") | |
{ | |
document.getElementById('p-subject').textContent = "* Please input your subject"; | |
document.getElementById('subject').style.border = "1px solid red"; | |
} | |
if(email.value == "") | |
{ | |
document.getElementById('p-email').textContent = "* Please input your email"; | |
document.getElementById('email').style.border = "1px solid red"; | |
} | |
if(textarea.value == "") | |
{ | |
document.getElementById('p-textarea').textContent = "* Please input your message "; | |
document.getElementById('textarea').style.border = "1px solid red"; | |
} | |
} | |
function formBlur(input) | |
{ | |
if(input.value != '') | |
{ | |
input.nextElementSibling.textContent = ""; | |
input.style.border = '2px solid green'; | |
} | |
} | |
</script> | |
</body> | |
</html> |