473,769 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to validate input data in array

vikas251074
198 New Member
I am using ASP
In my company, all employees have to sent materials out of premises. Any employee who need to sent material out will use this web application. In the first page, an employee enters firm name, vehicle no, driver name, purpose, persons taking out, received by, remarks. In the second page, employee enters no. of materials to be taken out. In the third page, displays no. of rows for entry of material details like material name, serial_no., qty, weight remarks.
I have written validation for all field. All validation works well. In the third page, validation works well when no. of material taken out is 1. When it is > 1, then no validation works.

Please suggest me, what to do?

I am giving you code for entry and validation.

Thanks and regards,
Vikas
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <title>Material Entry Page</title>
  4. <script language="javascript">
  5.  
  6. function check1(s)
  7. {
  8. var t
  9. var str=s
  10. len=str.length
  11. for(i=0;i<=len;i++)
  12. {
  13. if(str.charAt(i)==0 ||str.charAt(i)==1 ||str.charAt(i)==2 ||str.charAt(i)==3 ||str.charAt(i)==4 ||str.charAt(i)==5 ||str.charAt(i)==6 ||str.charAt(i)==7 ||str.charAt(i)==8 ||str.charAt(i)==9 )
  14. continue;
  15. }
  16. else
  17. {
  18. t=2
  19. return t;
  20. }
  21. }
  22. return 0;
  23. }
  24. function check(s)
  25. {
  26. var t
  27. var str=s    
  28. len=str.length
  29. if (len==0)
  30. {
  31. t=1
  32. return t;
  33. }
  34. else
  35. {
  36. for(i=0;i<=len;i++)
  37. {
  38. if(str.charAt(i)==0 ||str.charAt(i)==1 ||str.charAt(i)==2 ||str.charAt(i)==3 ||str.charAt(i)==4 ||str.charAt(i)==5 ||str.charAt(i)==6 ||str.charAt(i)==7 ||str.charAt(i)==8 ||str.charAt(i)==9 )
  39. {
  40. t=2
  41. return t;
  42. }
  43. else
  44. {
  45. continue;
  46. }
  47. }
  48. return 0;
  49. }
  50. }
  51. function check2(s)
  52. {
  53. var t
  54. var str=s    
  55. len=str.length
  56. if (len==0)
  57. {
  58. t=1
  59. return t;
  60. }
  61. else
  62. {
  63. for(i=0;i<=len;i++)
  64. {
  65. if(str.charAt(i)=="+" ||str.charAt(i)=="-" ||str.charAt(i)=="*"|| str.charAt(i)=="`" ||str.charAt(i)=="!" ||str.charAt(i)=="@" ||str.charAt(i)=="#" ||str.charAt(i)=="$" ||str.charAt(i)=="%" ||str.charAt(i)=="^" ||str.charAt(i)=="&" ||str.charAt(i)=="=" ||str.charAt(i)=="?" ||str.charAt(i)=="<" ||str.charAt(i)==">")
  66. {
  67. t=2
  68. return t;
  69. }
  70. else
  71. {
  72. continue;
  73. }
  74. }
  75. return 0;
  76. }
  77. }
  78. function checkmat()
  79. {
  80. var t,t1;
  81. var str=document.myform.mat.value
  82. t=check2(str);
  83. if(t==2)
  84. {
  85. document.myform.mat.select()
  86. alert("Special characters are not allowed.");
  87. }
  88. if(t==1)
  89. {
  90. document.myform.mat.select()
  91. alert("Material must be entered.");
  92. }
  93. }
  94. function checkcsno()
  95. {
  96. var str=document.myform.csno.value
  97. len=str.length
  98. if (len==0)
  99. {
  100. document.myform.csno.select()
  101. alert("Company serial number must be entered.")
  102. }
  103. }
  104. function checkdsno()
  105. {
  106. var str=document.myform.dsno.value
  107. len=str.length
  108. if (len==0)
  109. {
  110. document.myform.dsno.select()
  111. alert("Department serial number must be entered.")
  112. }
  113. }
  114. function checkqty()
  115. {
  116. var t,t1;
  117. var str=document.myform.qty.value
  118. t=check1(str);
  119. if(t==2)
  120. {
  121. document.myform.qty.select()
  122. alert("Please enter numbers only.")
  123. }
  124. if(str==0)
  125. {
  126. document.myform.qty.select()
  127. alert("Quantity must > 0.")
  128. }
  129. }
  130. function checkrem()
  131. {
  132. var t,t1;
  133. var str=document.myform.rem.value
  134. t=check2(str);
  135. if(t==2)
  136. {
  137. document.myform.rem.select()
  138. alert("Special characters are not allowed.")
  139. }
  140. }
  141. </script>
  142.  
  143.  
  144. <%
  145. Set CON = Server.CreateObject("ADODB.Connection")
  146. con.open "Provider=MSDAORA.1;dsn=ops;Password=op;User ID=outpass;Data Source=intradb;Persist Security Info=True"
  147. SET RS=SERVER.CREATEOBJECT("ADODB.RECORDSET")
  148. 'RS=CON.EXECUTE("select max(gp_no) from gps")
  149. 'gn=rs("max(gp_no)")
  150. gn=session("gno")
  151. %>
  152. <!-- #include file="Hdr.asp" -->
  153. <form name="myform" action="smaterial.asp" METHOD="POST">
  154.  
  155. <b>Gatepass Number : <font color="blue"><%=GN%></font> <input type="hidden" name="gno" value="<%=GN%>" >
  156. <br><br>
  157. <TABLE border=3 cellPadding=5 cellSpacing=5 width="80%">
  158. <tr>
  159. <TD align='center'><B>SNo.</B></TD> 
  160. <TD align='center'><B>Material Name</B></TD> 
  161. <TD align='center'><B>Company Serial Number</B></TD> 
  162. <TD align='center'><B>Department Serial Number</B></TD>
  163. <TD align='center'><B>Quantity<br>
  164. (Number only)</B></TD>
  165. <TD align='center'><B>Weight<br>
  166. (Number only)</B></TD>
  167. <TD align='center'><B>Remarks</B></TD>
  168. </tr> 
  169. <%
  170. k=request.form("mno")
  171. k=cdbl(k)
  172. for i=1 to k 
  173. %>
  174. <tr> 
  175. <TD ALIGN=CENTER><B><%=i%></TD> 
  176. <TD><input type ='text' style="width:250px" name='mat'size=50 onblur="checkmat()"></TD>
  177. <TD><input type ='text' style="width:110px" name='csno'size=10 value='N/A' onblur="checkcsno()"></TD>
  178. <TD><input type ='text' style="width:110px" name='dsno'size=14 value='N/A' onblur="checkdsno()"></TD>
  179. <TD><input type ='text' style="width:60px" name='qty'size=5 value=1 onblur="checkqty()"></TD>
  180. <TD><input type ='text' style="width:60px" name='wt'size=5 value=0></TD>
  181. <TD><input type ='text' style="width:225px" name='rem'size=50 value='N/A' onblur="checkrem()"></TD>
  182. </tr>
  183. <% 
  184. next 
  185. %>
  186. </table>
  187. <br>
  188. <center><input type="submit" style="width:150px" value="Add"></center>
  189. </form>
  190. </body>
  191. </html>
  192.  
May 26 '08 #1
18 2408
jhardman
3,406 Recognized Expert Specialist
It looks like the validation is actually being done in the javascript, not the ASP. I'll move this to the javascript forum.

Jared
May 26 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
Instead of the ASP code, can you please post the html code only, the one you get in view source? Post only the HTML part then, not the JavaScript. JS is already clear.
May 27 '08 #3
vikas251074
198 New Member
Instead of the ASP code, can you please post the html code only, the one you get in view source? Post only the HTML part then, not the JavaScript. JS is already clear.
Yes Sir. Here is my HTML code without JavaScript. I am eagerly waiting for your suggestion.

Thanks and regards,
Vikas

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Material Entry Page</title>
  3. <!--#include file="link_color.css"-->
  4. <!-- #include file="Hdr.asp" -->
  5. <form name="myform" action="smaterial.asp" METHOD="POST">
  6.  
  7. <b>Gatepass Number   : <font color="blue"><%=GN%></font> <input type="hidden" name="gno" value="<%=GN%>" >
  8. <br><br>
  9. <TABLE border=3 cellPadding=5 cellSpacing=5 width="80%">
  10.   <tr>
  11.     <TD align='center'><B>SNo.</B></TD> 
  12.     <TD align='center'><B>Material Name</B></TD> 
  13.     <TD align='center'><B>Company Serial Number</B></TD> 
  14.     <TD align='center'><B>Department Serial Number</B></TD>
  15.     <TD align='center'><B>Quantity<br>
  16.                          (Number only)</B></TD>
  17.     <TD align='center'><B>Weight<br>
  18.                          (Number only)</B></TD>
  19.     <TD align='center'><B>Remarks</B></TD>
  20.   </tr> 
  21.     <tr>    
  22.       <TD ALIGN=CENTER><B><%=i%></TD>  
  23.       <TD><input type ='text' style="width:250px" name='mat'size=50 onblur="checkmat()"></TD>
  24.       <TD><input type ='text' style="width:110px" name='csno'size=10 value='N/A' onblur="checkcsno()"></TD>
  25.       <TD><input type ='text' style="width:110px" name='dsno'size=14 value='N/A' onblur="checkdsno()"></TD>
  26.       <TD><input type ='text' style="width:60px" name='qty'size=5 value=1 onblur="checkqty()"></TD>
  27.       <TD><input type ='text' style="width:60px" name='wt'size=5 value=0></TD>
  28.       <TD><input type ='text' style="width:225px" name='rem'size=50 value='N/A' onblur="checkrem()"></TD>
  29.     </tr>
  30. </table>
  31. <br>
  32. <center><input type="submit" style="width:150px" value="Add"></center>
  33. </form>
  34. </body>
  35. </html>

Here line no. 21 to 29 is under loop using ASP code which has been removed.
If 1 material is taken out then loop will run 1 times. Here validation works.
If 2 material is taken out then loop will run 2 dtimes. Validation not works for > 1.
Line no. 23, 24, 25, 26 and 28 is using validation function which was built using JavaScript.
May 27 '08 #4
hsriat
1,654 Recognized Expert Top Contributor
Ok, the problem is, when you refer an element as
var str=document.my form.mat.value, it just assumes the first (or may be last, not sure) element in the form with this name.
So, it works only when there's one entry.
When more then one entries, it doesn't work.

For this, make reference as
Expand|Select|Wrap|Line Numbers
  1. var str = document.getElementsByName('mat');
  2. for (var i=0; i<str.length; i++) {
  3.     do_validation_for(str[i]);
  4. }
Hope you understand this.. :)

And instead of the function check, check1, check2, you can reduce that code into one line by using regExp.
May 27 '08 #5
vikas251074
198 New Member
I have written following function as per your suggestion. And this function is called in input tag of material name i.e. 23rd line of HTML code (without ASP code) posted here just above. But still it is not working. What wrong am I doing?

Thanks and regards,
Vikas

Expand|Select|Wrap|Line Numbers
  1. function checkmat()
  2. {
  3.   var t;
  4.   var str = new RegExp("\\w","i")
  5.   str = document.getElementsByName('mat');
  6.   if (str.length > 0)
  7.   {
  8.     for (var i=0; i<str.length; i++) 
  9.     {
  10.       if (RegExp.test(str[i]))
  11.       {
  12.         continue;
  13.       }
  14.       else
  15.       {
  16.         t=2;
  17.         break;
  18.       }
  19.     }
  20.     if(t==2)
  21.     {
  22.       document.myform.mat.select()
  23.       alert("Special characters are not allowed.");
  24.     }
  25.   else
  26.   {
  27.     document.myform.mat.select()
  28.     alert("Material must be entered.");
  29.   }
  30. }
May 27 '08 #6
hsriat
1,654 Recognized Expert Top Contributor
Oh, so you are calling this function onblur event?

Need to do a little modification then.
Expand|Select|Wrap|Line Numbers
  1. function checkmat(mat) {
  2.     if (mat.value=="") {
  3.         alert("Material must be entered");
  4.         mat.focus();
  5.         return;
  6.     }
  7.     else if (!mat.value.test(/^[\w\s]*$/i)) {
  8.         alert("Special characters are not allowed.");
  9.         mat.focus();
  10.         return;
  11.     }
  12.     return;
  13. }
And write checkmat(this) instead of checkmat().
May 27 '08 #7
vikas251074
198 New Member
Very very nice sir,
It is working now.
Now the validation message is displaying 'Material must be entered.' It is very good. Now the problem in this function is -
1) Else part is not working.
2) But it got into repeated message when clicks on second material row without entering first material. And it never comes out.

I have to use Ctrl+Alt+C to close the browser. Is there any idea to avoid this? Can I avoid user to go to second row without entering first row?

Thanks and regards,
Vikas
May 27 '08 #8
hsriat
1,654 Recognized Expert Top Contributor
But it got into repeated message when clicks on second material row without entering first material. And it never comes out.
It shouldn't. There's some other problem in the code.

Is there any idea to avoid this? Can I avoid user to go to second row without entering first row?
That can be done, but you don't really need that. There's some other problem in the code as I said.

Also, make all the validation functions in the code similar to the material validation one.
May 27 '08 #9
vikas251074
198 New Member
OK Sir,

But the problem lies in this part, because when user clicks on second material row which is blank and the first being blank, then it gives the message for both, When I clicks on OK for 'Material must be entered' then it gives message for second row, when I clicks on OK for 'Material must be entered' then it gives message for first row. This process repeats for forever. And now Ctlr+Alt+C to close the browser.

What should I do?

Thanks and regards,
Vikas
May 27 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
438
by: FabFreddy | last post by:
Hi, I can't find out what the problem is with the error message below! I get it when I go from one to another page with controls in these pages. Anyone knows??? THX Unable to validate data. Description: An unhandled exception occurred during the execution of the
0
5423
by: Amy | last post by:
Hi, I'm suddenly getting this error when I post back from my application. the application worked once, i added some code on one page (customizing a datagrid), and suddenly I'm getting this exception even on a completely separate page (that worked before and that I haven't changed). Page 1 has a Response.Redirect that goes to Page 2 (which has the changes), but I get the error even if I trigger a postback event on Page 1 and Page 2...
0
1820
by: Peter O'Reilly | last post by:
I receive the following error when I post a webpage: "Unable to validate error" - System.Web.HTTPException. The web page is an ASP WebForm page. I have a few controls on the page that when selected (e.g. ASP.NET calendar control, HTML radio/option buttons), a postback occurs. In addition, I have a input button, that when clicked, initiates a HTTP Post Request. Notably the input button utilizes client side javascript to change the
5
3278
by: sjl | last post by:
I've got an .aspx webform for searching my database. It basically takes user input and passes it as a parm into a stored proc to search a table. The results are returned in a SQLDataReader and bound to a datagrid on the same page. It works 90% of the time as expected. However, for some unknown reason, I randomly get the error below. The HttpException says there is an 'Invalid_Viewstate'. Ok, but why? I'm posting back to the same page. If...
0
1598
by: BuddyWork | last post by:
Hello, When setting the Web Gardens to 3 and I start browsing one of my asp.net page I get the following error shown below. I don't get the error when I set the Web Gardens to 1. Please note that I'm using Windows 2003 Server with .Net Framework 1.1 SP1. Error:
4
5767
by: Mike Fellows | last post by:
running IIS on a single server, hosting pages on an intranet basis, one single user out of 50 is having an unable to validate data issue how do i fix this (the microsoft KB is a little inconclusive) ? cheers mark this is the error message
6
3396
by: Solje | last post by:
Im developing an ASP.NET application used for maintinance purpose and it may be idle for some ours. The application crash with the error shown below when the user click on some contol in the appliaction. This crash occurs on every clients at same time, event for the client at the local server. I added some logging to the Application_Error method that contains following: Exception of type System.Web.HttpUnhandledException was thrown. at...
6
1653
by: inamul | last post by:
Hi Guys, I am am trying to validate multiple check box. It works fine when checkbox name is like chkSectionInterested but when i add to the name chkSectionInterested, then i can validate any more. I need to keep so that i can save data using php collected from this page. If i remove from checkbox name then php only gets last selected value from the check box please help. I have been looking for two days but nothin seems to work. ...
1
2845
by: irfanshariffa | last post by:
<html> <head> <script type="text/javascript" language="javascript"> function validate() { if (document.form.fname.value=="") { alert("Enter your Name"); document.form.fname.focus();
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.