• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 671
  • Last Modified:

recipient.length is null or not an object in javascript


<script language="JavaScript">
function chk(ob,num)
{
     var isCheck = ob.checked;
     var d=document.getElementsByTagName("input");
     for(var i=0;i<d.length;i++) {
       if (num == ob.name) {
         // Master box was checked
         if(d[i].name.indexOf((num))!=-1) d[i].checked=isCheck;
       } else {
         // Sub- box was checked
         if(d[i].name==num) d[i].checked=false;
       }
     }
}

function checkform(objForm)
{
     var i;
     var valid = false;
     var check_one;

     check = "" + objForm.recipients.length;

     if ( check != "undefined"  )
     {
         for ( i=0; i<objForm.recipients.length; i++ )
         {
             if ( objForm.recipients[i].checked == true )
             {
                 valid = true;
                 break;
             }
         }
     }
     else
     {
         if ( objForm.recipients.checked == true )
             valid = true;
     }

     if ( !valid )
         alert("Oops! You forgot to select Recipients!");

     return valid;
}
</script>

I/m gettint the recipients.length is null or not an object in javascript error....i'm using this script onSubmit event.....how to rectify this,,,,,
0
jagadeesh_motamarri
Asked:
jagadeesh_motamarri
  • 6
  • 4
  • 4
1 Solution
 
netsmithcentralCommented:
I can't be positive without seeing the HTML side of this page, but it looks like you're trying to refer to mulitiple elements named "recipients" as an array.  That's not how the DOM is designed... you have to refer to every element uniquely.  Maybe if you show us the HTML we can suggest an alternate?
0
 
jagadeesh_motamarriAuthor Commented:
Herez the complete code...

<%@ include file ="security.jsp"%>
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.lang.Integer" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.*" %>
<%@ page import="njit.capstone.proj.validations"%>
<%@ page import="njit.capstone.proj.C4isrDAO"%>


<%
      
      System.out.println("Now entered addSuspense");
      String req_count = (String)request.getAttribute("req_count")==null?"0":(String)request.getAttribute("req_count");
      
      //get the current date as initial date for start and end date, if Vector is not empty, then use date from Vector
      String[] monthDesc={"January","February","March","April","May","June","July","August","September","October","November","December"};
      
      
      String errMsg=(String)request.getAttribute("error") ==null ?"":(String)request.getAttribute("error");
      
      
      
        GregorianCalendar currentDay=new GregorianCalendar();            
      String currentYear=Integer.toString(currentDay.get(GregorianCalendar.YEAR));
      String currentMonth=Integer.toString(currentDay.get(GregorianCalendar.MONTH)+1);
      String currentDate=Integer.toString(currentDay.get(GregorianCalendar.DATE));
      
      
      String s_received_on_mm = currentMonth;
      String s_received_on_dd = currentDate;
      String s_received_on_yy = currentYear;
      
      
                  
      String due_mm = currentMonth;
      String due_dd = currentDate;
      String due_yy = currentYear;
      
      
      String internal_mm   = currentMonth;
      String internal_dd   = currentDate;
      String internal_yy   = currentYear;                  
      
      
      System.out.println("Step - 0");

%>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to Department of US Army - C4ISR</title>

<!-- Style Sheet -->

<link  href="stylesheet.css" type="text/css" media="all" rel="stylesheet" />

<style type="text/css">
<!--
.style4 {
      font-size: 16px;
      font-weight: bold;
}
-->
</style>

<script language="JavaScript">
function chk(ob,num)
{
     var isCheck = ob.checked;
     var d=document.getElementsByTagName("input");
     for(var i=0;i<d.length;i++) {
       if (num == ob.name) {
         // Master box was checked
         if(d[i].name.indexOf((num))!=-1) d[i].checked=isCheck;
       } else {
         // Sub- box was checked
         if(d[i].name==num) d[i].checked=false;
       }
     }
}

function checkform(objForm)
{
     var i;
     var valid = false;
     var check_one;

     check = "" + objForm.recipients.length;

     if ( check != "undefined"  )
     {
         for ( i=0; i<objForm.recipients.length; i++ )
         {
             if ( objForm.recipients[i].checked == true )
             {
                 valid = true;
                 break;
             }
         }
     }
     else
     {
         if ( objForm.recipients.checked == true )
             valid = true;
     }

     if ( !valid )
         alert("Oops! You forgot to select Recipients!");

     return valid;
}

function AddRowsToTable() {
 var tbl = document.getElementById('tblSample');
 var lastRow = tbl.rows.length;
 var iteration = lastRow;    

 if(iteration > 100) //change 4 to any number (suppose if u want only 10 files change 4 to 9)
 {
 alert("5 FILES ONLY");
 return;
 }
 var row = tbl.insertRow(lastRow);
 
 var cellRight = row.insertCell(0);
 var el = document.createElement('input');
 el.setAttribute('type', 'FILE');
 el.setAttribute('name', 'FILE');

 el.setAttribute('size', '40');
 cellRight.setAttribute('id',iteration)
 cellRight.appendChild(el);
// var aa = document.createElement("<a href='#' onClick='RemoveRowFromTable();return false;'>Remove Last</a>'");
 var aa = document.createElement("a");
 aa.setAttribute('href', '#');
var clickName = new Function("DeleteRow(this)");
aa.onclick = clickName;
 aa.innerHTML = "Remove";
 cellRight.appendChild(aa);
}
function DeleteRow(x)
{
     while (x.tagName.toLowerCase() !='tr')
     {
          if(x.parentElement)
             x=x.parentElement;
        else if(x.parentNode)
             x=x.parentNode;
        else
             return;
     }
     var rowNum=x.rowIndex;
     while (x.tagName.toLowerCase() !='table')
     {
          if(x.parentElement)
             x=x.parentElement;
        else if(x.parentNode)
             x=x.parentNode;
        else
             return;
     }
     x.deleteRow(rowNum);  
      return false;
}

function RemoveRowFromTable(rowid) {
//alert("sadfs");
 var tbl = document.getElementById(iteration);
 //var lastRow = tbl.rows.length;
 //if (lastRow > 1)
 tbl.deleteRow(rowid);
}
<!-- Begin
function firstWindow(viewForm) {
      var particleTitle=viewForm.articleTitle.value;      
      var particleText = viewForm.articleText.value;
      
      viewWindow = window.open("",'Window','width=600,height=350,left=200, top=200, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes');
      viewWindow.document.write("<html>");
      viewWindow.document.write("<STYLE TYPE='text/css'>");
      viewWindow.document.write("<!--");
      viewWindow.document.write("BODY");
      viewWindow.document.write("{COLOR:black; BACKGROUND-COLOR: white; font-size:11pt;font-family:arial;}");
      viewWindow.document.write(".redhead {FONT-WEIGHT: 700; FONT-SIZE: 12pt; COLOR: #da2325; FONT-FAMILY:Arial;}");      
      viewWindow.document.write(".graydate {COLOR: gray; FONT-WEIGHT: 700;FONT-STYLE:italic;FONT-SIZE:9pt;FONT-FAMILY:Arial;}");
      viewWindow.document.write(".graycontact {COLOR: gray; FONT-SIZE:10pt;FONT-FAMILY:Arial;}");
      viewWindow.document.write("--></STYLE>");                  

      viewWindow.document.write("<title> Preview of the article </title> <BODY>");
      viewWindow.document.write("<SPAN CLASS='redhead'>");
      viewWindow.document.write(particleTitle);
      viewWindow.document.write("</SPAN> <p> ");
      viewWindow.document.write(particleText);      
      viewWindow.document.write("</html>");
      viewWindow.document.close();
      viewWindow.focus();      
}



function ShowMoreInfo(){  
      var winl = (screen.width - 434) / 2;  
      var wint = (screen.height - 241) / 2;  
      window.open('moreInfo.html','' ,'width=434,height=241,top='+wint+',left='+winl+'', true);  
}



</script>

<script type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/dialog.js"></script>
<script type="text/javascript" src="htmlarea/lang/en.js"></script>

<style type="text/css">@import url(htmlarea/htmlarea.css);
a:link, a:visited { color: #00f; }
a:hover { color: #048; }
a:active { color: #f00;   }
textarea { background-color: #fff; }
</style>

<script language="JavaScript" type="text/javascript">
javascript:window.history.forward(1);
</script>

 <script type="text/javascript" defer="1">
      // All our custom buttons will call this function when clicked.
      // We use the buttonId parameter to determine what button
      // triggered the call.
      
      // FIXME!!! this should return false for IE < 5.5
      function checkBrowse() {
            //return false;
            if (HTMLArea.is_gecko) {
                  if (navigator.productSub < 20021201) {
                        //alert("You need at least Mozilla-1.3 Alpha.\n" +
                        //      "Sorry, your Gecko is not supported.");
                        return false;
                  }
                  if (navigator.productSub < 20030210) {
                        //alert("Mozilla < 1.3 Beta is not supported!\n" +
                        //      "I'll try, though, but it might not work.");
                        return false;      
                  }
            }
            return HTMLArea.is_gecko || HTMLArea.is_ie;
      };
      
      function clickHandler(editor, buttonId) {            
        switch (buttonId) {
          case "my":
            var html = prompt("Enter some HTML code here");
                if (html) {
            editor.insertHTML(html);
                }           
            break;
          case "my-date":
            editor.insertHTML((new Date()).toString());
            break;
          case "my-bold":
            editor.execCommand("bold");
            editor.execCommand("italic");
            break;
          case "my-hilite":
            editor.surroundHTML("<span class=\"hilite\">", "</span>");
            break;
        }
      };
      
      // Create a new configuration object
      var config = new HTMLArea.Config();
      
      // Register our custom buttons
      config.registerButton("my",  "Insert HTML code", "images/my.gif", false, clickHandler);
      config.registerButton("my-date", "Insert date/time", "my-date.gif", false, clickHandler);
      config.registerButton("my-bold", "Toggle bold/italic", "my-bold.gif", false, clickHandler);
      config.registerButton("my-hilite", "Hilite selection", "my-hilite.gif", false, clickHandler);
      
      // Append the buttons to the default toolbar
      //config.toolbar.push(["my-toc", "my-date", "my-bold", "my-hilite"]);      
      if(!document.all){ //Netscape Navigator Detected
            config.toolbar = [
            [ "fontname", "space",
              "fontsize", "space",
              "formatblock", "space",
              "bold", "italic", "underline", "separator",
              "strikethrough", "subscript", "superscript", "separator",
              "copy", "cut", "paste" ],
                        
            [ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
              "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
              "forecolor", "hilitecolor", "textindicator", "separator",
              "inserthorizontalrule", "createlink", "insertimage", "inserttable", "separator",
              "popupeditor", "separator", "showhelp", "my" ]
            ];
            
      }else{
            config.toolbar = [
            [ "fontname", "space",
              "fontsize", "space",
              "formatblock", "space",
              "bold", "italic", "underline", "separator",
              "strikethrough", "subscript", "superscript", "separator",
              "copy", "cut", "paste" ],
                        
            [ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
              "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
              "forecolor", "hilitecolor", "textindicator", "separator",
              "inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode", "separator",
              "popupeditor", "separator", "showhelp", "my" ]
            ];
      }
      // Replace an existing textarea with an HTMLArea object having the above config.
      if(checkBrowse()){
            var MyHTMLArea = new HTMLArea("id1", config);
        MyHTMLArea.generate();
            document.getElementById("texttitle").innerHTML = "<font face='Arial' size='2' color='#2C2C81'><b>Text - HTML Editor:</b><b> (Support IE 5.5 and higher, Netscape 7.1, Mozilla 1.3)<br><b> (If the Text Area doesn't appear, <A HREF='javascript:history.go(0)'>Click here to refresh the page</A>)</b>";
      }
    //HTMLArea.replace("id1");
      </script>




</head>
<%
      
      System.out.println("Step - 1");
response.setHeader("Cache-Control","no-store"); //HTTP 1.1

response.setHeader("Pragma","no-cache"); //HTTP 1.0

response.setDateHeader ("Expires", 0); //prevents caching at the proxy server

%>




<body>
c
<!-- Header logo-->
<table width="100%" border="0">
  <tr>
    <td width="8%" height="57" rowspan="3"><img src="Images/ArmySeal.gif" /></td>
    <td width="92%">&nbsp;      </td>
  </tr>
  <tr>
    <td height="10" style="font-family:arial;text-align:left;font-weight:bold;padding:3 0; margin-bottom:-1;"><span class="style4">Welcome to Department of US Army</span> </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

  <!-- Header logo ends here-->
<hr color="#D0B623" />
<table border="0" cellspacing="0" class="form-noindent">
  <tr>
    <td colspan="4" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td height="17" colspan="3" valign="top" class="color_D0B623">    </td>
    <td width="1073" rowspan="8" valign="top"><table width="100%" border="0" cellspacing="0">
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td width="2%" height="708">&nbsp;</td>
        <td width="96%" valign="top"><div  class="headings">
          <p>Add Suspense</p>
          </div>
             
              <div>
              <% if (errMsg != null) {%>
                     <div class="error"> <%=errMsg%></div>
                 <%}%>
              </div>
              <form  name="form" action="AddSuspenseHandler" id="form" method="post" onsubmit="return checkform(this);">
             
               
                <table width="686"  border="0" align="center" cellspacing="0" class="suspense_table form-noindent tabtext">
              <tr>
                <td colspan="2" bgcolor="#D0B623">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="2"><div align="center"><a href="http://add.yahoo.com/fast/help/us/edit/cgi_access"><img src="https://sec.yimg.com/i/space.gif" alt="Attention Blind or Visually Impaired Users. To complete this form you must enter a word that is part of an image. If you can't read the image, Yahoo is happy to help you create your account. A representative from customer care will need to contact you. To request assistance with registration, please read the Yahoo! Terms of Service located at http://docs.yahoo.com/info/terms. Once you have reviewed our policies, please provide your phone number and email address and send your request by visiting this URL - http://add.yahoo.com/fast/help/us/edit/cgi_access" border="0" height="1" width="1" /></a></div></td>
              </tr>
              <tr>
                <td width="110"><div align="right">Subject/Task Title: </div></td>
                <td width="570"><label>
                    <div align="left">
                      <input name="title" type="text" id="title"    size="50" value=""/>
                    </div>
                  </label></td>
              </tr>
              <tr>
                <td><div align="right">Summary/Synopsis of the Suspense: </div></td>
                <td><label>
                    <div align="left">
                      <label>
                      <textarea id='id1' name = "articleText" rows="18" cols="60"></textarea>
                      </label>
                    </div>
                  </label></td>
              </tr>
                  
      
              <tr>
                <td><div align="right">Tasker who issued the Suspense:</div></td>
                <td><label>
                    <div align="left">
                      <input name="tasker" type="text" id="tasker" size="45"    maxlength="45" value=""/>
                    </div>
                  </label></td>
              </tr>
              <tr>
                <td><div align="right">Suspense was Received on:</div></td>
                <td><label>
                    <div align="left">
                      <select name="s_received_on_mm">
                        <%for(int i=1;i<=12;i++){%>
                        <option value="<%=i%>"<%if(Integer.parseInt(s_received_on_mm)==i) out.println("SELECTED"); %> ><%=monthDesc[i-1]%>
                        <%}%>
                        </option>
                      </select>
/
<select name="s_received_on_dd">
  <%for(int i=1;i<=31;i++){%>
  <option <%if(Integer.parseInt(s_received_on_dd)==i) out.println("SELECTED"); %>><%=i%>
  <%}%>
  </option>
</select>
/
<select name="s_received_on_yy">
  <%for(int i=Integer.parseInt(currentYear);i<=Integer.parseInt(currentYear)+4;i++){%>
  <option <%if(Integer.parseInt(s_received_on_yy)==i) out.println("SELECTED"); %>><%=i%>
  <%}%>
  </option>
</select>
&nbsp;&nbsp;</div>
                  </label></td>
              </tr>
              <tr>
                <td><div align="right">Assigned Taskee:</div></td>
                <td><label>
                    <div align="left">
                      <input name="taskee" type="text" id="taskee" size="45" maxlength="45"    value=""/>
                    </div>
                  </label></td>
              </tr>
              <tr>
                <td height="25"><div align="right">Suspense Due Date: </div></td>
                <td><div align="left">
                    <select name="due_mm">
                      <%for(int i=1;i<=12;i++){%>
                      <option value="<%=i%>"<%if(Integer.parseInt(due_mm)==i) out.println("SELECTED"); %> ><%=monthDesc[i-1]%>
                      <%}%>
                      </option>
                    </select>
                  /
                  <select name="due_dd">
                    <%for(int i=1;i<=31;i++){%>
                    <option <%if(Integer.parseInt(due_dd)==i) out.println("SELECTED"); %>><%=i%>
                      <%}%>
                      </option>
                  </select>
                  /
                  <select name="due_yy">
                    <%for(int i=Integer.parseInt(currentYear);i<=Integer.parseInt(currentYear)+4;i++){%>
                    <option <%if(Integer.parseInt(due_yy)==i) out.println("SELECTED"); %>><%=i%>
                      <%}%>
                      </option>
                  </select>
                  &nbsp;&nbsp;</div></td>
              </tr>
              <tr>
                <td height="25"><div align="right">Internal Suspense Due Date: </div></td>
                <td><select name="internal_mm">
                    <%for(int i=1;i<=12;i++){%>
                    <option value="<%=i%>"<%if(Integer.parseInt(internal_mm)==i) out.println("SELECTED"); %> ><%=monthDesc[i-1]%>
                    <%}%>
                    </option>
                </select>
                  /
                  <select name="internal_dd">
                    <%for(int i=1;i<=31;i++){%>
                    <option <%if(Integer.parseInt(internal_dd)==i) out.println("SELECTED"); %>><%=i%>
                      <%}%>
                      </option>
                  </select>
                  /
                  <select name="internal_yy">
                    <%for(int i=Integer.parseInt(currentYear);i<=Integer.parseInt(currentYear)+4;i++){%>
                    <option <%if(Integer.parseInt(internal_yy)==i) out.println("SELECTED"); %>><%=i%>
                      <%}%>
                      </option>
                  </select>
                  &nbsp;&nbsp;</td>
              </tr>
              <tr>
                <td height="25"><div align="right">Additional Information: </div></td>
                <td><label>
                  <textarea name="additional_info" cols="80" rows="8" id="additional_info"></textarea>
                  </label>
                  &nbsp;</td>
              </tr>
              <tr>
                <td height="17"><div align="right">Recipients of the Suspense: </div></td>
                <td width="96%" valign="top" class="headings">
                        
                         <%
                              System.out.println("Step - 1");
                              List searchMap = new ArrayList();
                              searchMap = (List)request.getAttribute("searchMap");
                              String tempData ="";
                              String tempData_Key = "";
                              String errmsg ="";
                              if(searchMap == null || searchMap.size() == 0){
                                    errmsg = "Currently are no Chiefs in the C4iSR - Suspense Tracking System";
                                    
                        %>
                        
                        <h3 class="labeltxtb" align="center"><%out.write(errmsg);%></h3>
                        <%}      else{ %>
                        <table border="1" bordercolor="#D0B623" align="center" width="589" cellpadding="0" cellspacing="0" title="This table shows the results of the search query">
                        <tr class="labeltxtb">
                        <!-- Here Depending on the Option selected the sequence will be changed-->
                        <th><input type="checkbox" name="recipients" value="" onClick="chk(this,'recipients')"  /></th>
                        <th>FIRST NAME </th>
                        <th>LASTNAME</th>
                        <th>EMAIL</th>
                        </tr>
                        
                    <% }%>
                        <%
                  
                  
                  Iterator i = searchMap.iterator();
                  int j = 1;
      
                  
                  while(i.hasNext()){
                        Vector dataVector = (Vector)i.next();
                        if(dataVector !=null){
                        
                              int dataVectorSize = dataVector.size();
                              String id=dataVector.get(0).toString();
                              out.println("<tr>");
                        
                                    
                              out.println("<td class=\"labeltxt\" align=\"center\" >&nbsp;");
                              out.println("<input type=\"checkbox\" name = \"recipients\" value=\""+dataVector.get(3).toString()+"\"    onClick=\"chk(this,'list')\"    />");
                              out.println("&nbsp;</td>");
                              j++;
                              tempData_Key = dataVector.get(0)==null ?"" :dataVector.get(0).toString();
                              
                              for(int vectorIndex=1;vectorIndex<dataVectorSize;vectorIndex++){
                                    tempData = dataVector.get(vectorIndex)==null ?"" :dataVector.get(vectorIndex).toString();
                                    
                              
                                          
                                    out.println("<td class=\"labeltxt\" align=\"center\" >&nbsp;");
                                    out.println(tempData);
                                    out.println("&nbsp;</td>");
                                    
                                    
                              }// end of for loop
                              
                        
                              out.println("</tr>");
                        
                        
                        }// end of if loop
                        else
                        out.println("Unable to retrieve the data properly. please contact system administrator");
                        
                        
                  }//end of while loop      
                              

                                          %>
                        </table>                        </td>
              </tr>
              <tr>
                <td height="48"><div align="right">Additional Receipients: </div></td>
                <td><label>
                  <textarea name="ccbcc" cols="80" id="ccbcc"></textarea>
                </label></td>
              </tr>
              <tr>
                <td height="48"><div align="right">File Attachments </div></td>
                <td><table border="0" cellspacing="2" cellpadding="2" id="tblSample">
 <tr id="row">
  <td width="1" colspan="2"></td>
</tr>
</table>
<table border="0" cellspacing="2" cellpadding="2">
 <tr>

  <td><a href="javascript:AddRowsToTable();">Add File</a></td>
  </tr>
</table>
 </td>
              </tr>
              <tr>
                <td height="48">&nbsp;</td>
                <td><label>
                  <input type="reset" name="Reset" value="Reset" />
                </label>
                  <label>
                  <input type="submit" name="Submit2" value="Add Suspense" onclick="return checkform(this);" />
                  </label></td>
              </tr>
            </table>
                </form>
             
              </td>
        <td width="2%"><p>&nbsp;</p>
          <p>&nbsp;</p></td>
      </tr>
      <tr>
        <td height="16" colspan="3" valign="top">&nbsp;</td>
      </tr>
    </table>
      <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td width="24" height="98" class="color_D0B623">&nbsp;</td>
    <td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
  <div align="center"><a href="#" >Home</a></div>
</li>
<li >
  <div align="center"><a href=ForwardToAddSuspense target="_self" >Add Suspense</a></div>
</li>
<li>
  <div align="center"><a href="#">Search Suspense</a></div>
</li>
<li>
  <div align="center"><a href="#">Generate Report</a></div>
</li>
<li>
  <div align="center"><a href="#">Change Profile</a></div>
</li>
</ul>
</div></td>
    <td width="24" height="98" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td height="18" colspan="3" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td width="24" height="98" class="color_D0B623">&nbsp;</td>
    <td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
  <div align="center"><a href=ShowReqListHandler target="_self" >Authentication Requests (<font color="#FF0000"><b> <% out.println(req_count);%></b></font> ) </a></div>
</li>
<li>
  <div align="center"><a href=ForwardToAddUser target="_self" >Add New User </a></div>
</li>        
<li>
  <div align="center"><a href=#" >Delete/Deactivate User </a></div>
</li>
<li>
  <div align="center"><a href=ShowUserListHandler target="_self" >View all Users </a></div>
</li>
</ul>
</div></td>
    <td width="24" height="98" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td height="17" colspan="3" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td width="24" height="71" class="color_D0B623">&nbsp;</td>
    <td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
  <div align="center"><a href=ForwardToAddChief target="_self" >Add Chief</a></div>
</li>
<li>
  <div align="center"><a href="#">Delete/Deactivate Chief</a></div>
</li>
<li>
  <div align="center"><a href=ShowChiefListHandler target="_self" >View all Chiefs </a></div>
</li>
</ul>
</div></td>
    <td width="24" height="71" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td height="17" colspan="3" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
<table width="100%" border="0">
  <tr>
    <td><div class="footer" >
        <div align="center">©2006 US Army -      <a href="#">Terms of Use</a> - <a href="#">Privacy Policy</a> </div>
      </div>&nbsp;</td>
  </tr>
</table><p>&nbsp; </p>
</body>
</html>
..................................................

i'm using that piece of code to make sure that atleast one checkbox is selected by the user before submitting the form....any alternate method is also fine...if its working...thankz
0
 
netsmithcentralCommented:
Yep, that's the problem alright.  You have a couple of options.  You can rewrite the JSP while loop that creates the recipient checkboxes uses an incrementing variable to give every checkbox a unique name/id, then refer to them as such in the javascript.  Potentially an easier option (and the one I'll demonstrate), change the JSP to give the checkboxes all the same class, then operate on them that way.

First, edit the JSP generation line; out.println("<input type=\"checkbox\" class = \"recipients\" value=\""+dataVector.get(3).toString()+"\"    onClick=\"chk(this,'list')\"    />");

Now, edit the JS function that calls them:
function checkform(objForm)
{
     var i;
     var valid = false;
     var check_one;

     check = document.getElementsByTagName('INPUT');

     for ( i=0; i<checklength; i++ )
     {
         if (check.className == 'recipients' && check.type == 'checkbox')
         {
             valid = true;
             break;
         }
     }
if ( !valid )
    alert("Oops! You forgot to select Recipients!");

return valid;
}

That should do it for you.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
jagadeesh_motamarriAuthor Commented:
but i can't rename the jsp code...becoz i'm using the name=\"recipients\" in a servlet to get the list.....
0
 
netsmithcentralCommented:
Can you add the class parameter?  So:
 out.println("<input type=\"checkbox\" name = \"recipients\" value=\""+dataVector.get(3).toString()+"\"    onClick=\"chk(this,'list')\"    class = \"recipients\"    />");
0
 
jagadeesh_motamarriAuthor Commented:
says checklength is undefined and is not working as anticipated...
0
 
ZvonkoSystems architectCommented:
Check this:


function checkform(objForm){
     check = objForm.recipients;
     if(!check){
        alert("No element with the name 'recipients' on the form!");
        return false;
     }

     if ( check.length)  {
         for (var i=0; i<check.length; i++ )  {
             if (check[i].checked == true ) return true;
         }
     } else {
         if ( check.checked == true ) return true;
     }
     alert("Oops! You forgot to select Recipients!");
     return false;
}


0
 
netsmithcentralCommented:
Oops, looks like I forgot a dot.

function checkform(objForm)
{
     var i;
     var valid = false;
     var check_one;

     check = document.getElementsByTagName('INPUT');

     for ( i=0; i<check.length; i++ )
     {
         if (check.className == 'recipients' && check.type == 'checkbox')
         {
             valid = true;
             break;
         }
     }
if ( !valid )
    alert("Oops! You forgot to select Recipients!");

return valid;
}
0
 
jagadeesh_motamarriAuthor Commented:
it should not pop up when atleast one of them is checked......but its popping other wise also..
0
 
ZvonkoSystems architectCommented:
did you check my checker?
0
 
jagadeesh_motamarriAuthor Commented:
No Zvonk0......its popping a message even if  i checked...
0
 
ZvonkoSystems architectCommented:
Poping "Oops..." or poping "No elements..."

0
 
jagadeesh_motamarriAuthor Commented:
No element....
0
 
ZvonkoSystems architectCommented:
You mean: No element with the name 'recipients' on the form!

So my question to you is: Are you sure you have checkboxes withn the name "recipients" on your form?

Copy that name string and search it trough your BROWSER html source and see how many checkboxes did you got wit that name. Be also aware they all have to be lowercase.

0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 6
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now