Skip to content

Instantly share code, notes, and snippets.

@ggagosh
Created October 12, 2019 06:00
Show Gist options
  • Save ggagosh/47e24c52ab6354419d4b318c94b5bba2 to your computer and use it in GitHub Desktop.
Save ggagosh/47e24c52ab6354419d4b318c94b5bba2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h1>Hello</h1>
<form name="myform" onsubmit="return validateMyForm();">
<input id="fname" placeholder="First Name" type="text" name="fname">
<input type="submit" name="Submit" value="submit">
</form>
<table>
<thead>
<th>First Name</th>
</thead>
<tbody id="MaBody">
<tr>
<td>Giorgi</td>
</tr>
</tbody>
</table>
<script src="code.js"></script>
</body>
</html>
function validateMyForm()
{
var nameValue = document.getElementById("fname").value;
var element = document.getElementById("MaBody");
var newElement = '<tr><td>'+ nameValue + '</td></tr>'
element.insertAdjacentHTML( 'beforeend', newElement )
document.getElementById("fname").value = '';
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment