Created
December 8, 2018 17:32
-
-
Save guibranco/17e72ed6098f2ed9d34aa2790a2263a5 to your computer and use it in GitHub Desktop.
Loop de PHP & JS - Davidson Web - PHP Brasil - Facebook - https://www.facebook.com/groups/nao.tem.biscoito/permalink/10161478291675160/
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
<html> | |
<body> | |
<script> | |
function soma(numeroDoForm) { | |
var campos = document.querySelectorAll("input[id^='campo-" + numeroDoForm + "-']"); | |
var resultado = document.getElementById("resultado-" + numeroDoForm); | |
var soma = 0; | |
for(var i = 0; i < campos.length; i++) | |
soma += campos[i].value * 1; | |
resultado.value = soma; | |
} | |
</script> | |
<?php | |
for ($i=0; $i < 3; $i++){ | |
?> | |
<form name="form-<?php echo $i; ?>"> | |
<input id="campo-<?php echo $i; ?>-1"> | |
<input id="campo-<?php echo $i; ?>-2"> | |
<input id="campo-<?php echo $i; ?>-3" > | |
<input id="resultado-<?php echo $i; ?>" onmouseover="soma(<?php echo $i; ?>)" readonly><br> | |
</form> | |
<?php } ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment