[Javascript] struts form using javascript code

Chris Tifer christ at saeweb.com
Wed Mar 3 08:08:46 CST 2004


Ok, we're getting somewhere. Now if you can tell us what's supposed to happen and what event triggers the ".length is not" error message, then we'll make it somewhere. I imagine it's when you click this:

<input type=checkbox name="driver_all" value="Check All" onClick="check(this.form.list)">

In the future, I suggest you put all of this information in one e-mail for a speedy response. Otherwise, we spend our time just trying to determine what it's supposed to do and not why it's not doing it.

Chris Tifer

P.S. Looked at it a little closer and it seems that you only have one "list" elements (that's a bad name that I would avoid) and 1-item elements are not a collection, hence, there is no .length on them.  I'm guessing that's your problem. To test, add a second list item (and then change that name to something that might not one day become a reserved keyword.


  ----- Original Message ----- 
  From: Samyukta Akunuru 
  To: [JavaScript List] 
  Sent: Tuesday, March 02, 2004 5:52 PM
  Subject: Re: [Javascript] struts form using javascript code


  Here it is...

  Thanks,
  Sam.




  <html>
  <head>
  <style><!--
  body,td,a,p,.h{font-family:times new roman,arial,sans-serif;}
  .h{font-size: 20px;}
  .q{text-decoration:none; color:#0000cc;}
  //-->
  </style>

  <SCRIPT LANGUAGE="JavaScript">
  var checkflag = "false";
  function check(field) {
  if (checkflag == "false") {
  for (i = 0; i < field.length; i++) {
  field[i].checked = true;}
  checkflag = "true";
  return "Uncheck All"; }
  else {
  for (i = 0; i < field.length; i++) {
  field[i].checked = false; }
  checkflag = "false";
  return "Check All"; }
  }

  function set(target) {document.forms[0].dispatch.value=target;}
  </script>
  </head>
  <body>
  <table border="0" width="100%">
     <tr>
     <td bgcolor="00007D"  align="center">
        <font color=white size="6"><b><u>Drivers</u></b></font>
      </td>
  </tr>
  </table>
  <table>
  <form name="driversDisplayForm" method="post" action="//deleteDriver.do">  
     <tr>
  <td align="right">
  <!-- use onSubmit-- javascript-->
        <input type="hidden" name="finalDeleteArray"
                      value="return getCheckedItems();">
                      <input type="button" name="Delete" value= "Delete" onClick="getCheckedItems()">    
      </td>
    <td align="right">
        <!--html:submit property="submit" value="Add"/-->
        <input type="button" name="Add" value= "Add" onClick="window.location.href='driver_new.jsp'">
      </td>
     
     
      </tr>
  </table>
  <!--html:form action="display" name="displayForm"-->  
  <table border="1" width="100%">
       
  <tr>
  <th><input type=checkbox name="driver_all" value="Check All" onClick="check(this.form.list)"></th>
  <th><a href="drivers.jsp">Last name</a></th>
  <th><a href="drivers.jsp">First Name</a></th>
  <th><a href="drivers.jsp">Middle Name</a></th>
  <th><a href="drivers.jsp">Clock #</a></th>
  <th><a href="drivers.jsp">Supervisor</a></th>
  <th><a href="drivers.jsp">Notes</a></th>
  </tr>
    
        <tr align="left">
        <td align="center">
        <input type=checkbox name="list" value="1">
        </td>
     <td align="center">
               peterson
     </td>
     <td align="center">
              peter
     </td>
     <td align="center">
              j
     </td>
     <td align="center">
              <a href="driverDisplay.do?employeeID=ppeterson">
         ppeterson
         </a>
     </td>
     <td align="center">
               green, rachel j(rgreen)
     </td>
     <td align="center">
                      new addition

     </td>
  </tr>
     
  </table>
  </form> 
  <SCRIPT LANGUAGE="JavaScript">
  function getCheckedItems()
  {
    var value = false;
    menus = new Array;
    var msg = "";
    var checkBoxes = document.forms[0].elements["list"];

  for(var i = 0; i < checkBoxes.length; i++)
    {
      if(checkBoxes[i].checked)
      {
        menus = menus+","+i;
   
   value = true;    
      }
    }
  menusChopped = menus.substr(1,menus.length-1);//chop leading comma
  deleteArray = new Array;
  deleteArray  = menusChopped.split(",");
  finalDeleteArray  = new Array;

   for (i=0;i<deleteArray.length;i++){
    finalDeleteArray[i]= deleteArray[i];
    alert(finalDeleteArray[i]);
   }

  if(!value)
      alert("Check at least one of the checkboxes, thanks.");

  //this.form.action="http://myserver.com/searchById/submit.do";//fix this
  //window.location.href='deleteDriver.do';
  return finalDeleteArray;
  }
  </script>

  </body>
  </html>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20040303/7ff530b9/attachment.htm>


More information about the Javascript mailing list