Copiar Campos com mesmo ID
by Rapha Souza
HTML
<script src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<html>
<head>
<title></title>
<script type="text/javascript">
function copy_form()
{
id('nome_copy').value = id('nome').value;
id('idade_copy').value = id('idade').value;
}
function id( el ){
return document.getElementById( el );
}
window.onload = function()
{
id('copiar').onclick = function()
{
copy_form();
}
}
</script>
</head>
<body>
Form Original:
<form action="" method="post">
<input type="text" name="nome" id="nome" value="Bruno Rocha" />
<input type="text" name="idade" id="idade" value="21 anos" />
</form>
Form Copia:
<form action="" method="post">
<input type="text" name="nome" id="nome_copy" />
<input type="text" name="idade" id="idade_copy" />
</form>
<input type="button" name="copiar" id="copiar" value="copiar" />
</body>
</html>
CSS
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}