Connecting Tech Pros Worldwide Forums | Help | Site Map

Add Row (DOM) with onClick Function

Newbie
 
Join Date: Jun 2006
Posts: 2
#1: Jun 16 '06
I have been using the dom to add a row to my form for awhile now, but now I need to do some validation to make sure certain check boxes aren't checked with other check boxes. Now of course it works with the first row, but after I add a row, the Function does not work (no runtime error or anything).
So first is my Function do the validation, second is my code for adding new row (this is where I'm having trouble, maybe with the setAttribute??), and third is my HTML code.
Thanks!!!
1. Function for validation
Expand|Select|Wrap|Line Numbers
  1.  <script language="javascript"> 
  2. function checkAccess(j) {
  3.     xgu = eval("document.step2.general_" + j); 
  4.     xadmin = eval("document.step2.admin_" + j); 
  5.     xvo = eval("document.step2.viewonly_" + j); 
  6.     if (xgu.checked == true && xvo.checked == true && xadmin.checked == true){
  7.         alert('You cannot have General User AND Admin AND View Only Selected');
  8.         xgu.checked = true;
  9.         xadmin.checked = false;
  10.         xvo.checked = false;
  11.     }
  12.     if (xgu.checked == true && xadmin.checked == true) {
  13.         alert('You cannot have General User AND Admin Selected');
  14.         xgu.checked = true;
  15.         xadmin.checked = false;
  16.         xvo.checked = false;
  17.     }
  18. if (xgu.checked == true && xvo.checked == true){
  19.         alert('You cannot have General User AND View Only Selected');
  20.         xgu.checked = true;
  21.         xadmin.checked = false;
  22.         xvo.checked = false;
  23.     }    
  24. }
  25. </script>
  26.  
2. Add new Row
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="JavaScript" type="text/javascript">
  3. function addRowToTable() 
  4. {
  5.     var tbl = document.getElementById('table2a');
  6.     var lastRow = tbl.rows.length;
  7.     // if there's no header row in the table, then iteration = lastRow + 1
  8.     var iteration = lastRow;
  9.     var row = tbl.insertRow(lastRow);
  10.  
  11.     // sbcuid cell
  12.     var cellbox = row.insertCell(0);    
  13.     cellbox.style.backgroundColor = "#F4F4F4";
  14.     var box = document.createElement('input');
  15.     box.setAttribute('type', 'text');
  16.     box.setAttribute('name', 'txtRow_' + iteration);
  17.     box.setAttribute('id', 'txtRow_' + iteration);
  18.     box.setAttribute('size', '5');
  19.     box.setAttribute('maxlength', '6');
  20.  
  21.     cellbox.appendChild(box);
  22.  
  23.     // General User cell
  24.     var cellgeneral = row.insertCell(1);
  25.     cellgeneral.style.backgroundColor = "#F4F4F4";
  26.     cellgeneral.align='center';
  27.     var general = document.createElement('input');
  28.     general.setAttribute('type', 'checkbox');
  29.     general.setAttribute('name', 'general_' + iteration);
  30.     general.setAttribute('id', 'general_' + iteration);    
  31.     general.setAttribute('value','1');
  32.     var myfcn = 'checkAccess(' + iteration + ')';
  33.     general.setAttribute('onClick',myfcn);
  34.     cellgeneral.appendChild(general);    
  35.  
  36.     // admin cell
  37.     var celladmin = row.insertCell(1);
  38.     celladmin.style.backgroundColor = "#F4F4F4";
  39.     celladmin.align='center';
  40.     var admin = document.createElement('input');
  41.     admin.setAttribute('type', 'checkbox');
  42.     admin.setAttribute('name', 'admin_' + iteration);
  43.     admin.setAttribute('id', 'admin_' + iteration);    
  44.     admin.setAttribute('value','1');
  45.     var myfcn = 'checkAccess(' + iteration + ')';
  46.     admin.setAttribute('onClick',myfcn);
  47.     celladmin.appendChild(admin);
  48.  
  49.     // viewonly cell
  50.     var cellviewonly = row.insertCell(2);
  51.     cellviewonly.style.backgroundColor = "#F4F4F4";
  52.     cellviewonly.align='center';
  53.     var viewonly = document.createElement('input');
  54.     viewonly.setAttribute('type', 'checkbox');
  55.     viewonly.setAttribute('name', 'viewonly_' + iteration);
  56.     viewonly.setAttribute('id', 'viewonly_' + iteration);    
  57.     viewonly.setAttribute('value','1');
  58.     var myfcn = 'checkAccess(' + iteration + ')';
  59.     viewonly.setAttribute('onClick',myfcn);
  60.     cellviewonly.appendChild(viewonly);
  61. }
  62. </script>
  63.  
3. HTML Code
Expand|Select|Wrap|Line Numbers
  1.  
  2. <table width="100%" cellpadding="2" cellspacing="1" id="table2a">
  3.                                                 <tr bgcolor="FDFFE6">
  4.                                                     <td width="29%"><b>SBCUID</b></td>    
  5.                                                     <td align="center" width="2%">
  6.                                                         <b> 
  7.                                                         <SCRIPT LANGUAGE="javascript" type="text/javascript">
  8.                                                         <!--
  9.                                                         document.write ("<span style=\"color:black;font-size=80%;\" title=\" General User is being listed on the calendar. \" class='popup1'>General User</span>");
  10.                                                         //-->
  11.                                                         </SCRIPT>
  12.                                                         </b>    
  13.                                                     </td>                                                            
  14.                                                     <td align="center" width="2%">
  15.                                                         <b>
  16.                                                         <SCRIPT LANGUAGE="javascript" type="text/javascript">
  17.                                                         <!--
  18.                                                         document.write ("<span style=\"color:black;font-size=80%;\" title=\" Admin is having the ability to update/delete the calendar and it's users. A User CAN have View Only Access and Admin Access \" class='popup1'>Admin</span>");
  19.                                                         //-->
  20.                                                         </SCRIPT>
  21.                                                         </b>    
  22.                                                     </td>                        
  23.                                                     <td align="center" width="2%" nowrap>
  24.                                                         <b>
  25.                                                         <SCRIPT LANGUAGE="javascript" type="text/javascript">
  26.                                                         <!--
  27.                                                         document.write ("<span style=\"color:black;font-size=80%;\" title=\" View Only is having access to the calendar, but will NOT be included in the list of users. A User CAN have View Only Access and Admin Access \" class='popup1'>View Only</span>");
  28.                                                         //-->
  29.                                                         </SCRIPT>
  30.                                                         </b>    
  31.                                                     </td>            
  32.                                                 </tr>                
  33.                                                 <tr bgcolor="F4F4F4">
  34.                                                     <td>
  35.                                                         <input type="text" name="txtRow_1" id="txtRow_1" size="5" maxlength="6">                                                                
  36.                                                     </td>
  37.                                                     <td align="center" align="center">
  38.                                                         <input type="checkbox" name="general_1" value="1" id="general_1" checked onClick="checkAccess('1')" />
  39.                                                     </td>
  40.                                                     <td align="center" align="center">
  41.                                                         <input type="checkbox" name="admin_1" value="1" id="admin_1" onClick="checkAccess('1')" />
  42.                                                     </td>
  43.                                                     <td align="center" align="center">
  44.                                                         <input type="checkbox" name="viewonly_1" value="1" id="viewonly_1" onClick="checkAccess('1')" />
  45.                                                     </td>                                                            
  46.                                                 </tr>        
  47.                                             </table>
  48.  
  49.                                 <input type="button" class="XPButton" value="Add A User" onclick="addRowToTable();" />
  50.  

Newbie
 
Join Date: Jun 2006
Posts: 2
#2: Jun 16 '06

re: Add Row (DOM) with onClick Function


This is what was needed:
general.onclick=function() {checkAccess(iteration);}

For Example:
Expand|Select|Wrap|Line Numbers
  1. // General User cell
  2. var cellgeneral = row.insertCell(1);
  3. cellgeneral.style.backgroundColor = "#F4F4F4";
  4. cellgeneral.align='center';
  5. var general = document.createElement('input');
  6. general.setAttribute('type', 'checkbox');
  7. general.setAttribute('name', 'general_' + iteration);
  8. general.setAttribute('id', 'general_' + iteration); 
  9. general.setAttribute('value','1');
  10. general.onclick=function() {checkAccess(iteration);}
  11. cellgeneral.appendChild(general);
Newbie
 
Join Date: Oct 2006
Posts: 8
#3: Oct 5 '06

re: Add Row (DOM) with onClick Function


I have gone through the "Add Row at run time."
There i just adding textfield and option field .
But i need to add a combobox with some values.
Please give how to add it instead of textfield.
Newbie
 
Join Date: Oct 2006
Posts: 8
#4: Oct 7 '06

re: Add Row (DOM) with onClick Function


Please specify how to add a combo in a new added cell.
Newbie
 
Join Date: Oct 2006
Posts: 8
#5: Nov 1 '06

re: Add Row (DOM) with onClick Function


How to delete a row from that table
Reply