[Javascript] Checkbox values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike1961
    New Member
    • Apr 2008
    • 66

    [Javascript] Checkbox values

    [Javascript] Checkbox values

    Hello.

    I have a problem with this code ASP / Javascript.

    The problem is JavaScript; try this LINK and select value cespiti

    1) With ASP language is populated a secondary form, generated by a main form with a series of checkboxes, text fields and select;

    2) Selecting different checkbox from a secondary form and compiled other fields, this values must be copied to a single field hidden in the principal form;

    If the checkbox returned by the query SQL, is unique, the string:

    Code:
     return LG.substr();
    is right and compiled values in the field hidden in principal form.

    But if the checkbox returned by the query SQL are different, the string:

    Code:
     return LG.substr();
    response with:

    Code:
    undefined;undefined;undefined;undefined
    Can you help me?

    kind regards
    mike
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can you explain what you mean by "checkbox returned by the query SQL is unique/different"?

    Comment

    • Mike1961
      New Member
      • Apr 2008
      • 66

      #3
      Originally posted by acoder
      Can you explain what you mean by "checkbox returned by the query SQL is unique/different"?
      checkbox unique in the secondary form:

      Code:
      <input type="checkbox" name="DETTAGLIO_1" value="CS7">

      checkbox different in the secondary form:

      Code:
      <input type="checkbox" name="DETTAGLIO_1" value="CS7">
      
      <input type="checkbox" name="DETTAGLIO_2" value="CS20">
      
      <input type="checkbox" name="DETTAGLIO_3" value="NCS24">

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        How do you generate the LG string?

        Comment

        • Mike1961
          New Member
          • Apr 2008
          • 66

          #5
          Originally posted by acoder
          How do you generate the LG string?
          Open this link:
          Start your new business venture with a great domain name. A trusted source for domains since 2005.


          Select "cespiti" value in the main form;

          In the popup page I have secondary form;

          Select checkbox and the other fields and click in the button "salva".

          Generate LG string

          Comment

          • Mike1961
            New Member
            • Apr 2008
            • 66

            #6
            I have change the code.

            This is main form:

            Code:
            <html>
            <head>
            <script language="javascript" type="text/javascript">
            <!--
            
            // Variabile globale contenente l'istanza 'window' del popup corrente
            var popup = null;
             
            function Forum(fld, tbl, col, w, h)
            {
              var pw = Math.floor((screen.width - w) / 2);
              var ph = Math.floor((screen.height - h) / 2);
             
              // Crea il popup solo se non è già stato aperto
              if (!popup || popup.closed) popup = window.open("popup.htm?f=" + fld + "&t=" + tbl + "&c=" + col, "scelte",
                                                              "width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);
             
              // Attiva il popup (portalo in primo piano)
              if (popup) popup.focus();
            }
            
            //-->
            </script>
            
            </head>
            
            <body> 
            
            <form name=myform action="?upload=1" method="POST">
            
            <INPUT TYPE="hidden" NAME="dati_aggiuntivi" VALUE="xxxx">
            
            <select size="1" name="dettaglio_visita" style="font-size: 8 pt; font-family: Verdana" onchange="Forum(this.value, 'tbl_mac_visite_ispettive_dett', 'DETTAGLIO_VERIFICA', 700, 500); this.selectedIndex = 0;">">
            
            <option>Seleziona</option>
            <option value="14-Cespiti">Cespiti</option>
            </select> 
            
            </form>
            
            </body>
            </html>

            This is secondary form:

            Code:
              
              
            <html>
            <head>
            
            <title>Popup</title>
            <link rel=stylesheet href=/mac/css/applicativi.css>
            <link rel=stylesheet href=/mac/css/menu.css>
            
            <script language="javascript" type="text/javascript">
            <!--
            
            function insertf1(f1) {
               
                    window.opener.document.myform.dati_aggiuntivi.value=f1;
                    //alert("Dati aggiuntivi correttamente salvati.");
                    //window.close();
                    
                    return f1.substr();
               
            }
            
            //-->
            </script>
            
            </head>
            
            <body>
             
            <form name="myform">
            
            
            
            <p>&nbsp;</p>
            
            <div align="center">
              <table border="0" id="table1">
                
            <tr>
               <td class=blub align="center">Sottodettaglio<br>Verifica</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">Eseguita?</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">Esito della verifica</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">Totale items<br>verificati</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">di cui<br>items KO</td>
            </tr>   
            
            
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
            </tr>   
            
            <tr>
               <td class=blub align="center">CS7</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_1" value="CS7"></td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            <select size="1" name="Esito">
               <option>Seleziona Esito</option>
               <option value="Sufficiente">Sufficiente</option>
               <option value="Insufficiente">Insufficiente</option>
               <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
               <option value="Dettagliato in verbale">Dettagliato in verbale</option>
            </select></td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center"><input type="text" name="ITEMS_1" size="5"></td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center"><input type="text" name="ITEMS_KO_1" size="5"></td>
            
            </tr>
                  
            
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
            </tr>   
            
            <tr>
               <td class=blub align="center">CS20</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_2" value="CS20"></td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            <select size="1" name="Esito">
               <option>Seleziona Esito</option>
               <option value="Sufficiente">Sufficiente</option>
               <option value="Insufficiente">Insufficiente</option>
               <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
               <option value="Dettagliato in verbale">Dettagliato in verbale</option>
            </select></td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center"><input type="text" name="ITEMS_2" size="5"></td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center"><input type="text" name="ITEMS_KO_2" size="5"></td>
            
            </tr>
                  
            
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
            </tr>   
            
            <tr>
               <td class=blub align="center">NCS24</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_3" value="NCS24"></td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            <select size="1" name="Esito">
               <option>Seleziona Esito</option>
               <option value="Sufficiente">Sufficiente</option>
               <option value="Insufficiente">Insufficiente</option>
               <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
               <option value="Dettagliato in verbale">Dettagliato in verbale</option>
            </select></td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center"><input type="text" name="ITEMS_3" size="5"></td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center"><input type="text" name="ITEMS_KO_3" size="5"></td>
            
            </tr>
                  
            
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
            </tr>   
            
            <tr>
               <td class=blub align="center">NCS25</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_4" value="NCS25"></td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            <select size="1" name="Esito">
               <option>Seleziona Esito</option>
               <option value="Sufficiente">Sufficiente</option>
               <option value="Insufficiente">Insufficiente</option>
               <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
               <option value="Dettagliato in verbale">Dettagliato in verbale</option>
            </select></td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center"><input type="text" name="ITEMS_4" size="5"></td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center"><input type="text" name="ITEMS_KO_4" size="5"></td>
            
            </tr>
                  
            
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
            </tr>   
            
            <tr>
               <td class=blub align="center">CS21</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_5" value="CS21"></td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            <select size="1" name="Esito">
               <option>Seleziona Esito</option>
               <option value="Sufficiente">Sufficiente</option>
               <option value="Insufficiente">Insufficiente</option>
               <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
               <option value="Dettagliato in verbale">Dettagliato in verbale</option>
            </select></td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center"><input type="text" name="ITEMS_5" size="5"></td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center"><input type="text" name="ITEMS_KO_5" size="5"></td>
            
            </tr>
                  
            
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
            </tr>   
            
            <tr>
               <td class=blub align="center">CS29</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_6" value="CS29"></td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            <select size="1" name="Esito">
               <option>Seleziona Esito</option>
               <option value="Sufficiente">Sufficiente</option>
               <option value="Insufficiente">Insufficiente</option>
               <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
               <option value="Dettagliato in verbale">Dettagliato in verbale</option>
            </select></td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center"><input type="text" name="ITEMS_6" size="5"></td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center"><input type="text" name="ITEMS_KO_6" size="5"></td>
            
            </tr>
                  
            
              
              </td>
                </tr>
            
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            &nbsp;</td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center">&nbsp;</td>
            
            </tr>
                  
            <tr>
               <td class=blub align="center" colspan="9">
               <div align="center">
                 <table border="0" id="table3">
                   <tr>
                     <td><p align="center">
                        <a href="javascript:insertf1(document.myform.SOTTODETTAGLIO_VERIFICA_6.value+';'+document.myform.Esito.value+';'+document.myform.ITEMS_6.value+';'+document.myform.ITEMS_KO_6.value)">
                        <img border="0" src="salva_button.gif" width="84" height="16"></a></td>
                     <td>&nbsp;</td>
                     <td><p align="center"><a href="javascript:void(0);" onclick="window.close()">
                         <input type="image"src="chiudi_button.gif" border="0" align="middle" name="I5"></a></td>
                   </tr>
                 </table>
               </div>
               </td>
            
            </tr>
                  
            <tr>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">&nbsp;</td>
               <td class=blub align="center">
            
            &nbsp;</td>
            <td class=blub align="center">&nbsp;</td>
            
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center">&nbsp;</td>
            <td class=blub align="center">&nbsp;</td>
            
            </tr>
                  
              </table>
            </div>
            
            </form>
             
            </body>
            </html>

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              The problem is line 286:
              [code=html]<a href="javascrip t:insertf1(docu ment.myform.SOT TODETTAGLIO _VERIFICA_6.val ue+';'+document .myform.Esito.v alue+ ';'+document.my form.ITEMS_6.va lue+';'+documen t.myf orm.ITEMS_KO_6. value)">[/code]What do you actually want to happen? For example, if I select checkbox 1, do you want anything to appear, or do you always want to pass the last row data?

              Comment

              • Mike1961
                New Member
                • Apr 2008
                • 66

                #8
                Originally posted by acoder
                The problem is line 286:
                [code=html]<a href="javascrip t:insertf1(docu ment.myform.SOT TODETTAGLIO _VERIFICA_6.val ue+';'+document .myform.Esito.v alue+ ';'+document.my form.ITEMS_6.va lue+';'+documen t.myf orm.ITEMS_KO_6. value)">[/code]What do you actually want to happen? For example, if I select checkbox 1, do you want anything to appear, or do you always want to pass the last row data?
                Ok I understand.

                I need insert in the string:

                [code=html]<a href="javascrip t:insertf1(docu ment.myform.SOT TODETTAGLIO _VERIFICA_6.val ue+';'+document .myform.Esito.v alue+ ';'+document.my form.ITEMS_6.va lue+';'+documen t.myf orm.ITEMS_KO_6. value)">[/code]

                all the values selected in the secondary form and insert this string in the hidden field of the main form; whether a value or more values.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Is there a particular reason why the elements are named differently? You can use the same name, just not the same ID. If you have the same name, you can use document.getEle mentsByName() to get a list/array of elements which you can loop over. Check the checked property of the checkboxes to see if that row is one of the selected ones to pass the values through.

                  Comment

                  • Mike1961
                    New Member
                    • Apr 2008
                    • 66

                    #10
                    Originally posted by acoder
                    Is there a particular reason why the elements are named differently? You can use the same name, just not the same ID. If you have the same name, you can use document.getEle mentsByName() to get a list/array of elements which you can loop over. Check the checked property of the checkboxes to see if that row is one of the selected ones to pass the values through.

                    Ok, I try this but response with error 'Object required', why?:


                    Code:
                    function insertf1(stringa) 
                    
                    {
                    
                       var s = "";
                       for( var i = 0; i < 7; i++)
                     
                      {
                       
                          s += "," + document.getElementById('test_'+i).value;
                            
                       }   
                            window.opener.document.myform.dati_aggiuntivi.value=s;
                            
                            return s.substr();
                       
                    }
                    
                    <select size="1" id=test_1" name="test_1">
                    ...
                    </select>
                    
                    <select size="1" id=test_2" name="test_2">
                    ...
                    </select>
                    
                    <select size="1" id=test_3" name="test_3">
                    ...
                    </select>
                    
                    <input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_1" value="NCS43">
                    
                    <input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_2" value="NCS44">
                    
                    <input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_3" value="NCS28">
                    
                    <a href="#" onclick="insertf1();return false;">

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      You're starting from 0 and the IDs start from 1.

                      Comment

                      • Mike1961
                        New Member
                        • Apr 2008
                        • 66

                        #12
                        Originally posted by acoder
                        You're starting from 0 and the IDs start from 1.
                        Error not change:

                        Code:
                        function insertf1(stringa) 
                         
                        {
                         
                           var s = "";
                           for( var i = 1; i < 7; i++)
                         
                          {
                           
                              s += "," + document.getElementById('test_'+i).value;
                                
                           }   
                                window.opener.document.myform.dati_aggiuntivi.value = s;
                                
                                return s.substr();
                           
                        }

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          You're not passing anything to insertF1, so you can remove stringa.

                          In the above code, you have only 3 elements while the loop loops till 6.

                          Comment

                          • Mike1961
                            New Member
                            • Apr 2008
                            • 66

                            #14
                            Originally posted by acoder
                            You're not passing anything to insertF1, so you can remove stringa.

                            In the above code, you have only 3 elements while the loop loops till 6.
                            Sorry, I don't understand.

                            I do not know how many fields I will have on the form secondary...

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              Then the 7 should be replaced by a dynamic value generated from the server-side which changes depending on the number of fields.

                              Comment

                              Working...