Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    585

    while con document.write document.getelementbyid

    Ciao a Tutti,

    ho una form con diversi campi i cui valori devono essere richiamati tramite funzione,
    attivata con un click sul pulsante

    <head>
    <script type="text/javascript">
    var h = 28;
    function check_r() { while (h > 0) { document.write(""+h+"
    "); h--; } }
    </script>
    </head>

    <form method="POST" name="FrontPage_Form_cu">
    ...
    <tr><td>
    <textarea rows="1" name="sent_1" id="sent_1" cols="22"><%=objRS("Sent_1")%></textarea>
    </td>
    <td>
    <textarea rows="1" name="sent_2" id="sent_2" cols="22"><%=objRS("Sent_2")%></textarea>
    </td>
    ....
    <td>
    <textarea rows="1" name="sent_28" id="sent_28" cols="22"><%=objRS("Sent_28")%></textarea>
    </td>
    .....
    <td><button onclick="check_r()">Check</button></td>
    .....
    </form>


    Schiacciando il pulsante "Check" vedo correttamente i numeri da 28 a 1 in ordine decrescente;
    e fin qui va bene ...

    vorrei pero' che al posto dei numeri mi venissero stampati a video i valori seguenti:

    function check_r() { while (h > 0) { document.write(""+document.getElementById('sent_'+ h).value+"
    "); h--; } }

    con la seguente sintassi:

    function check_r() { while (h > 0) { document.write(""+document.getElementById('sent_1' ).value+"
    "); h--; } }

    ne vedo uno solo e scritto una sola volta, mentre mi apsettavo di vederlo ripetuto 28 volte ...

    e ho provato in diversi modi, tra cui la creazione di un array, ma proprio non riesco a visualizzare gli altri valori ....

    Grazie mille in anticipo !!!

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2010
    Messaggi
    3,660
    non devi utilizzare document.write che va a sovrascrivere tutto ciò che è presente nella pagina, appendi i valori ad un contenitore con innerHTML o con i metodi del dom.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    585
    Grazie Vindav,

    ho provato in questo modo e funziona, pero' non mi soddisfa:

    function check_r() { var list_arr = new Array();
    list_arr[0]=document.getElementById('sent_1').value;
    list_arr[1]=document.getElementById('sent_2').value;
    list_arr[2]=document.getElementById('sent_3').value;
    list_arr[3]=document.getElementById('sent_4').value;
    list_arr[4]=document.getElementById('sent_5').value;
    list_arr[5]=document.getElementById('sent_6').value;
    list_arr[6]=document.getElementById('sent_7').value;
    list_arr[7]=document.getElementById('sent_8').value;
    list_arr[8]=document.getElementById('sent_9').value;
    list_arr[9]=document.getElementById('sent_10').value;
    list_arr[10]=document.getElementById('sent_11').value;
    list_arr[11]=document.getElementById('sent_12').value;
    list_arr[12]=document.getElementById('sent_13').value;
    list_arr[13]=document.getElementById('sent_14').value;
    list_arr[14]=document.getElementById('sent_15').value;
    list_arr[15]=document.getElementById('sent_16').value;
    list_arr[16]=document.getElementById('sent_17').value;
    list_arr[17]=document.getElementById('sent_18').value;
    list_arr[18]=document.getElementById('sent_19').value;
    list_arr[19]=document.getElementById('sent_20').value;
    list_arr[20]=document.getElementById('sent_21').value;
    list_arr[21]=document.getElementById('sent_22').value;
    list_arr[22]=document.getElementById('sent_23').value;
    list_arr[23]=document.getElementById('sent_24').value;
    list_arr[24]=document.getElementById('sent_25').value;
    list_arr[25]=document.getElementById('sent_26').value;
    list_arr[26]=document.getElementById('sent_27').value;
    list_arr[27]=document.getElementById('sent_28').value;

    for (var h=0; h<list_arr.length; h++) { document.write(""+list_arr[h]+"
    "); }
    }

    Perche' se di valori ne ho 100 devono scrivere 100 elementi di un array a mano ??

    Non c' e' un automatismo ??

    Sono riuscito adesso in parte a risolverlo cosi': mi da' errore qui ....

    function check_r() { var list_arr = new Array();
    for (var h=0; h<28; h++) { list_arr[h]=document.getElementById('sent_'+h+1 ).value; }
    for (var h=0; h<list_arr.length; h++) { document.write(""+list_arr[h]+"
    "); }
    }

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    585
    Risolto !!!

    function check_r() { var list_arr = new Array();
    for (var h=0; h<28; h++) { list_arr[h]=document.getElementById('sent_'+(h+1)).value; }
    for (var h=0; h<list_arr.length; h++) { document.write(""+list_arr[h]+"
    "); } }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.