Results 1 to 6 of 6

Thread: javascript: only allow 1 check per id property[SLOW RESOLUTION]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    javascript: only allow 1 check per id property[SLOW RESOLUTION]

    I have a form with a number of rows and each row has a checkbox that will pass a value on. I also am having a different ID value for each checkbox unless it is a related row. Does anyone know if I can only allow 1 checkbox to be checked per unique ID?

    You will see in my code below that I would only allow one row checked between Row1 and Row2 since they both have an ID of chkAdd[a]. Row3 and Row4 are fine since they only have one unique ID value.

    If anyone could help I would be greatful.
    Thanks in advance.

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <html>
    <head>
    <title>ID Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    function fnCompareCheckboxes(obj){
    	var vTotalChd = 0;
    	var vMax = document.frmUnMapped.chkAdd.length;
    
    	for (var vIdx =0; vIdx < vMax; vIdx++){
    		if (eval("document.frmUnMapped.chkAdd.checked") == true){
    			vTotalCkd += 1;
    		}
    	}
    	if (vTotalChd > 1){
    		alert("1 Choice only for this");
    		obj.checked = false;
    	}
    }
    </script>
    </head>
    
    <body>
    <form action="" method="post" name="frmUnMapped" id="frmUnMapped">
      <table width="650" border="1" cellspacing="0" cellpadding="0">
        <tr> 
          <td>Row1</td>
          <td><input name="chkAdd" type="checkbox" id="chkAdd[a]" value="1" onClick="fnCompareCheckboxes(this)"></td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>Row2</td>
          <td><input name="chkAdd" type="checkbox" id="chkAdd[a]" value="2" onClick="fnCompareCheckboxes(this)"></td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>Row3</td>
          <td><input name="chkAdd" type="checkbox" id="chkAdd[b]" value="3" onClick="fnCompareCheckboxes(this)"></td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td>Row4</td>
          <td><input name="chkAdd" type="checkbox" id="chkAdd[c]" value="4" onClick="fnCompareCheckboxes(this)"></td>
          <td>&nbsp;</td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    Last edited by lleemon; Jun 10th, 2004 at 07:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width