Current location: Hot Scripts Forums » General Web Coding » JavaScript » how to validate mutiple rows using the same input text


how to validate mutiple rows using the same input text

Reply
  #1 (permalink)  
Old 09-24-03, 08:28 PM
Han84 Han84 is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
how to validate mutiple rows using the same input text

Hi everyone,
I have a problem validating mutiple results using the same input text.
For example,
I use a for loop to display 5 rows of input text
User is require to key in a value in each of the 5 rows
But when i try to validate the 5 rows to check for empty field
The javascript is only able to validate only 1 row of result
Even if it is 10 rows, it only can validate 1 row of result
In other word, the javascript is only able to validate one row of result at any
one time.
How can i validate all the rows using javascript?

Below is the code that i am doing

asp Code:
  1. <form name="main_form" method="post" target="_blank" action="process_coa.asp" onsubmit="javascript:return checkform(this);">
  2.  
  3.  
  4. <% if product = "DBE" then %>
  5.  
  6. <tr>
  7.     <td align=center width=100 class=tableborder>
  8.     <font class="font"><b>MFG<br>LOT#</b></font>
  9.     </td>
  10.  
  11.     <td align=center width=100 class=tableborder style="border-left:0px">
  12.     <font class="font"><b>Loading<br>Date</b></font>
  13.     </td>
  14.  
  15.     <td  align=center width=100 class=tableborder style="border-left:0px">
  16.     <font class="font"><b>Vessel Name</b></font>
  17.     </td>
  18.  
  19.     <td  align=center width=100 class=tableborder style="border-left:0px">
  20.     <font class="font"><b>Voyage</b></font>
  21.     </td>
  22.  
  23.     <td  align=center width=100 class=tableborder style="border-left:0px">
  24.     <font class="font"><b>Tank No</b></font>
  25.     </td>
  26.  
  27.     <td  align=center width=100 class=tableborder style="border-left:0px">
  28.     <font class="font"><b>Quantity<br>Tonne</b></font>
  29.     </td>
  30. </tr>
  31.  
  32. <%
  33. tempinput1=(Request.Form("lotno_arraystring"))
  34. lotno_array=split(tempinput1,", ")
  35. %>
  36.  
  37.  
  38.  <%
  39.    '=============================================================================
  40.    '                      Display the selected lot/lots
  41.    '=============================================================================
  42.       for each x in lotno_array
  43.        
  44.        'retrieve data from sql
  45.       
  46.        set rs4 = server.createobject("ADODB.recordset")
  47.      sql4 = "select * from dbelabresult where lotno = '" & trim(x) & "'"
  48.     rs4.open sql4, cn, 3, 3, 1 %>
  49.  
  50.     <tr>
  51.         <!------------ display lot no -------->
  52.         <td  align=center class=tableborder style="border-top:0px">
  53.            <font class="font"><b><%=x%></b></font>
  54.         </td>
  55.        
  56.    
  57.         <!------------ display loading date -------->
  58.         <td  align=center class=tableborder style="border-left:0px;border-top:0px">
  59.           <input type=text readonly=true class="mediumfont" style="width:90;border:0;text-align:center;" name="loaddate<%=trim(x)%>">
  60.           <a href="javascript:show_calendar('main_form.loaddate<%=trim(x)%>');" onmouseover="window.status='Date Picker';return true;" onmouseout="window.status='';return true;">
  61.           <img style="border:0px;position:relative;left:-2;top:2;" src="../images/cal.gif">
  62.           </a>
  63.         </td>
  64.  
  65.         <!------------ display vesselName -------->
  66.         <td  align=center class=tableborder style="border-left:0px;border-top:0px">
  67.           <input type=text name="vesselname<%=x%>"  class="mediumfont" style="width:100;border:0;">
  68.         </td>
  69.  
  70.        
  71.         <!------------ display voyage -------->
  72.         <td  align=center class=tableborder style="border-left:0px;border-top:0px">
  73.           <input type=text name="voyage<%=x%>" class="mediumfont" style="width:100;border:0;">
  74.         </td>
  75.    
  76.         <!------------ display tankno -------->
  77.         <td  align=center class=tableborder style="border-left:0px;border-top:0px">
  78.            <input type=text name="tankno<%=x%>" class="mediumfont" style="width:100;border:0;">
  79.         </td>
  80.  
  81.         <!------------ display weight -------->
  82.         <td  align=center class=tableborder style="border-left:0px;border-top:0px">
  83.           <input type=text name="quantitytonne<%=x%>" class="mediumfont" style="width:100;border:0;" >
  84.         </td>
  85.  
  86.         <!------------ display max -------->
  87.         <td  align=center class=tableborder style="border:0;">
  88.           <font color=navy class="font">&nbsp;&nbsp;Max: <%=rs4("quantity")%></font>
  89.         </td>
  90.     </tr>
  91.    
  92.     <!-----------------------  Verification for DBE ------------------------------->
  93.     <script language="javascript">
  94.  
  95.     function checkform()
  96.     {
  97.        var error_message;
  98.  
  99.        error_message = "Please complete the following fields\n";
  100.       
  101.      
  102.        if (document.main_form.loaddate<%=x%>.value == "")
  103.        {
  104.          error_message = error_message + "\n - loaddate";
  105.        }
  106.        if (document.main_form.tankno<%=x%>.value =="")
  107.        {
  108.          error_message = error_message + "\n - tankno";
  109.        }
  110.        if (document.main_form.vesselname<%=x%>.value == "")
  111.        {
  112.          error_message = error_message + "\n - vessel name";
  113.        }
  114.        if (document.main_form.voyage<%=x%>.value == "")
  115.       {
  116.         error_message = error_message + "\n - voyage";
  117.       }
  118.       if (document.main_form.quantitytonne<%=x%>.value == "" )
  119.       {
  120.         error_message = error_message + "\n - weight";
  121.       }
  122.       if (parseInt(document.main_form.quantitytonne<%=x%>.value ) != document.main_form.quantitytonne<%=x%>.value )
  123.       {
  124.           
  125.         error_message = error_message + "\n - Enter number for weight";
  126.       } 
  127.       if (error_message == "Please complete the following fields\n")
  128.       {
  129.         return true;
  130.       }
  131.       else
  132.       {
  133.         alert (error_message);
  134.         return false;
  135.       }
  136.    
  137.  }
  138. </script>
  139. <% rs4.close() : set rs4 = nothing %>
  140.  
  141.      
  142. <% next %>
  143.  
  144. <% end if %>

Last edited by TwoD; 08-02-07 at 04:32 PM. Reason: Please use the proper wrappers when pasting code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-02-07, 10:14 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi,

It is only validating the first row, because all 5 function get the same name:

Code:
function checkform()
{
    ........ check row 1
}
Code:
function checkform()
{
    ........ check row 2
}
When you submit the form, you run function checkform(). Javascript will allways take the top function, so always row 1.

You need to change your javascript to loop through the rows and take it out of your recordset loop, so it doesnt get added 5 times. Simple example:

Code:
function checkform()
{
var error_message;

error_message = "Please complete the following fields\n";

for(var i=1;i ==5;i++)
{
var loaddate = document.main_form.loaddate + i;
if(loaddate.value == "") {
error_message = error_message + "\n - loaddate is missing for record no." + i;
} } if (error_message == "Please complete the following fields\n") {
return true;
} else {
alert (error_message);
return false; } }

Last edited by Yeroon; 08-02-07 at 10:16 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to enabled or disabled input text using a checkbox Han84 HTML/XHTML/XML 1 10-13-03 09:46 AM
displaying all duplicate records in my table. dsumpter PHP 6 09-02-03 11:54 AM


All times are GMT -5. The time now is 10:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.