[Javascript] Checkbox values

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

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

    Yes but this is already done:

    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.valu  e = s;
            
            return s.substr();
       
    }
    
    ...
    
    <form name="form">
    
    <% 
      rs.MoveFirst()
      Do While Not rs.EOF    
    %>
    
    
    <input type="checkbox" name="DETTAGLIO" value="<%=rs("DETTAGLIO")%>">
    
    <select size="1" id="test_<%=list%>" name="test_<%=list%>">
    ...
    </select>
    
    <select size="1" id="test_<%=list%>" name="test_<%=list%>">
    ...
    </select>
    
    <select size="1" id="test_<%=list%>" name="test_<%=list%>">
    ...
    </select>
    ...
    
    
    <%  
        rs.MoveNext()
      Loop
    %>
    
    ...
    
    <a href="#" onclick="insertf1();return false;">

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #17
      I meant on line 6, the 7 should be replaced by a dynamic value.

      You have three select elements, but the code loops till 6, so it would be trying to access "test_4", "test_5", "test_6" which don't exist.

      Comment

      • Mike1961
        New Member
        • Apr 2008
        • 66

        #18
        Originally posted by acoder
        I meant on line 6, the 7 should be replaced by a dynamic value.

        You have three select elements, but the code loops till 6, so it would be trying to access "test_4", "test_5", "test_6" which don't exist.
        OK, please acoder try this page htm:

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #19
          I don't think you've made any changes since the last time I checked. The code looks and behaves the same.

          If you're using unique IDs, use document.getEle mentById(). If you're using names, use document.getEle mentsByName(). Alternatively, you could use document.getEle mentsByTagName( "input") and then check the type/name.

          Comment

          • Mike1961
            New Member
            • Apr 2008
            • 66

            #20
            Originally posted by acoder
            I don't think you've made any changes since the last time I checked. The code looks and behaves the same.

            If you're using unique IDs, use document.getEle mentById(). If you're using names, use document.getEle mentsByName(). Alternatively, you could use document.getEle mentsByTagName( "input") and then check the type/name.

            Your help is not the help I think
            However, thanks.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #21
              Something lost in translation?

              I've seen the link, but the changes that you're showing in this thread are not reflected in the link. Also, the popup page is a .html file while you've shown that you're using ASP.

              Comment

              • Mike1961
                New Member
                • Apr 2008
                • 66

                #22
                Originally posted by acoder
                Something lost in translation?

                I've seen the link, but the changes that you're showing in this thread are not reflected in the link. Also, the popup page is a .html file while you've shown that you're using ASP.
                No problem acoder, problem solved:

                Code:
                function Re(){
                
                var f=document.getElementById('id_form')
                var stringa=''
                
                for(var k=0;k<f.elements.length;k++){
                  stringa+=f.elements[k].value+',';
                }
                
                  window.opener.document.myform.dati_aggiuntivi.value = stringa
                  alert("OK!");
                  window.close();
                
                }
                
                ...
                
                <form id="id_form" name="myform">
                
                ...
                
                <a href="#" onclick="Re();">...</a>

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #23
                  Oh, so you wanted all the fields in the form?

                  Anyway, glad to hear that you've managed to solve it.

                  Comment

                  Working...