0
I have a problem here. I’m wanting to make a file in which you write name, phone, problem, etc and then the filled information is printed in a standard mask. But I need the same information to appear in two different masks, in case you put the same variable in two different places. There’s the whole code if you can help me.
<html>
<head>
<title>Teste</title>
</head>
<body>
Nome <input id='nome' type='text' value='' onkeyup="insere()" />
Cont 1 <input id='fixo' type='text' value='' onkeyup="insere()" />
Cont 2 <input id='contato' type='text' value='' onkeyup="insere()" />
Problema <input id='problema' type='text' value='' onkeyup="insere()" />
<br><br><br>
problema continua
<br><br><br>
<p>Cliente: <span id="cliente"></span><br>
Contatos: <span id="tel"></span>\<span id="cont"></span><br>
descrição do problema: <span id="pro"></span></p>
<br><br><br>
problema resolvido
<br><br><br>
<p>Cliente: <span id="cliente"></span><br>
Contatos: <span id="tel"></span>\<span id="cont"></span><br>
descrição do problema: <span id="pro"></span></p>
</body>
<script type="text/javascript">
var cliente = document.getElementById('cliente');
var cli = document.getElementById('nome');
var tel = document.getElementById('tel');
var fone = document.getElementById('fixo');
var cont = document.getElementById('cont');
var tato = document.getElementById('contato');
var pro = document.getElementById('pro');
var blema = document.getElementById('problema');
function insere() {
var nome = cli.value;
if (nome == '') nome = 0;
cliente.innerHTML = nome;
var fixo = fone.value;
if (fixo == '') fixo = 0;
tel.innerHTML = fixo;
var contato = tato.value;
if (contato == '') contato = 0;
cont.innerHTML = contato;
var problema = blema.value;
if (problema == '') problema = 0;
pro.innerHTML = problema;
}
</script>
</html>
You have more than one element with the same id, which is bad practice. Thus, when you make the selection by id only the element of the first occurrence is returned.
– G. Bittencourt