473,513 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Validation

65 New Member
hi,

i have 20 madatory text boxes in one page.and i want to do validation using javascript.For that i am calling following function in button click.

Expand|Select|Wrap|Line Numbers
  1. function validate()
  2. {
  3.  var obj1 = document.getElementById('<%=txtMovie.ClientID%>').id; 
  4.  
  5.          for(var i=1;i<20;i++)
  6.            {
  7.                  var txtID = "obj" + i;
  8.                var txtBox= document.getElementById(txtID);
  9.  
  10.               if(txtID.value.length == 0)
  11.                 {
  12.                  alert("something");;
  13.                    return false;           
  14.              }
  15.           }    
  16. }
  17.  
But in this line i am not able to get the control
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(txtID)
.

How can i do this??
any help??

Regards,
Veena
Oct 14 '09 #1
8 1091
acoder
16,027 Recognized Expert Moderator MVP
Show the corresponding HTML. Are you sure the IDs of the text boxes are "obj1", "obj2", etc.?
Oct 14 '09 #2
veenna
65 New Member
hi acoder,

thank u for reply.

IDs of text boxes are different.In the above function i will be declaring obj1 ,obj2 as variables and i will assign ids to it.

Expand|Select|Wrap|Line Numbers
  1. var obj1 = document.getElementById('<%=txtMovie.ClientID%>');            
  2. var obj2 = document.getElementById('<%=txtCMovie.ClientID%>'); 
  3. var obj3 = document.getElementById('<%=txtNieMovie.ClientID%>'); 
  4. var obj4 = document.getElementById('<%=txtRelDate.ClientID%>'); 
  5. var obj5= document.getElementById('<%=txtLimDate.ClientID%>'); 

So i want to find the control in foor loop.

regards
veena
Oct 14 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
In that case, try:
Expand|Select|Wrap|Line Numbers
  1. var txtBox = window["obj" + i];
Oct 14 '09 #4
veenna
65 New Member
I tried with ur code but value is undefined.
Oct 14 '09 #5
RamananKalirajan
608 Contributor
Why can you get the objects by

Expand|Select|Wrap|Line Numbers
  1. var inpObj = document.getElementsByTagName('input');
  2. for(var i=0;i<inpObj.length;i++)
  3. {
  4.    if(inpObj.type="text"||inpObj.type="TEXT")
  5.     {
  6.          //do Validation
  7.     }
  8. }
Thanks and Regards
Ramanan Kalirajan
Oct 14 '09 #6
Dormilich
8,658 Recognized Expert Moderator Expert
@RamananKalirajan
this code won't work as intended...

Expand|Select|Wrap|Line Numbers
  1. for(var i=0;i<inpObj.length;i++)
  2. {
  3.    // note the == and the NodeList variable
  4.    if("text" == inpObj[i].type.toLowerCase())
  5.     {
  6.          //do Validation
  7.     }
  8. }
Oct 14 '09 #7
veenna
65 New Member
But i cant use the above code because i have to display different messages based on text box id.

thanks
veena
Oct 14 '09 #8
Dormilich
8,658 Recognized Expert Moderator Expert
the do something like
Expand|Select|Wrap|Line Numbers
  1. var message = {
  2.   id_1: "fool",
  3.   id_2: "idiot",
  4.   // and so on
  5. };
  6. // validation
  7. alert(message[inpObj[i].id]);
Oct 14 '09 #9

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

Similar topics

5
2658
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
9
4005
by: tzigone | last post by:
hello, i use asp.net validation controls in my site. i wonder whether usin javascript validation will fasten page load speed? there are currently lots of requiredfieldvalidator now is it better t...
111
14256
by: Retlak | last post by:
The recommended (on dozens of websites) and effective (works in Netscape, MSIE, Mozilla, probably others) way to detect if a browser has Javascript turned off is to put this in the <head>: ...
2
1427
by: GIMME | last post by:
Background ... I've created a web application that allows a user to create an HTML application from IE. The application itself creates an XML representation of a XHTML form. The XHTML...
5
2121
by: Allan M. | last post by:
I have a series of select boxes that must be populated client side, because they interact with each other. The design specification calls for these boxes to be updated without having to make a...
5
2627
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
8
3623
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
27
4681
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
6
3269
by: Peter Afonin | last post by:
Hello, I'm creating an application in ASP.NET 1.1. I need to check whether at least one checkbox in my datagrid has been checked. To do this, I'm using Javascript - I'm adding this code to...
5
1906
by: Peter Afonin | last post by:
Hello, I'm not an expert in Javascript, so I'm seeking an advice. As I mentioned in my previous post, I use Javascript to check whether at least one checkbox in the datagrid has been checked....
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
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...
0
7535
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...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5683
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,...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.