Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP][JavaScript]Pętla for oraz zmienna.
Forum PHP.pl > Forum > Przedszkole
codefun
Witam serdecznie.
Jestem nowy na tym forum. Chciałbym się nauczyć programować w języku js oraz php. Mam pewien problem ze swoim kodem. Wrzucam kod do podglądu:

CODE
<script>
function agefunction() {
var a = document.getElementById("age").value;

for ( var a<9; a++) {
document.getElementById("age").value;
var ages = a+1;

document.write(""+ages+"");
}


}
</script>


<input type="text" onkeyup="agefunction()">
<input type="text" id="age" value="ile masz lat?" onkeyup="agefunction()">



Chodzi o to że jak wpisze w input powiedzmy liczbe 5 to chce żeby mi się wyświetlały cyfry: 5,6,7,8,9. Chce aby to się działo dynamicznie.
_Borys_
  1. <!DOCTYPE HTML>
  2. <meta http-equiv="content-type" content="text/html" charset="utf-8"/>
  3. <script type="text/javascript">
  4. function agefunction(a) {
  5. var p = document.getElementById('ages');
  6. if (/^\d$/.test(a)) {
  7. var x = 0;
  8. var ages = [];
  9. for (; a <= 9; a++) {
  10. ages[x++] = a;
  11. }
  12. p.textContent = ages.join();
  13. } else {
  14. p.textContent = '';
  15. }
  16. }
  17. </head>
  18.  
  19. <input type="text" id="age" placeholder="ile masz lat ?" onkeyup="agefunction(this.value);"/>
  20. <p id="ages"></p>
  21.  
  22. </body>
  23. </html>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.