Hi......
Hello experts please give me a sample code for validating many text box with same.i knew for validate a number but i couldnt get how to validate for many text box with same name.
regards
satheesh kannan
Hi......
Hello experts please give me a sample code for validating many text box with same.i knew for validate a number but i couldnt get how to validate for many text box with same name.
regards
satheesh kannan
Since you haven't made it clear what we are validating on, you will have to make up your own rule for the highlighted part. Or you could tell me what we are validating on, and I could tell you what to put there:
Then in the opening tag of your form:Code:<script type="text/javascript"> function val_many(f, n){ for (var e = f.elements, i = e.length - 1; i > -1; --i) if (e[i].type && e[i].type == 'text' && e[i].name && e[i].name == n &&!(e[i].value something)){ alert('Some Message'); e[i].focus(); return false; } return true; } </script>
HTML Code:<form action="whatever" onsubmit="return val_many(this, 'some_name');">
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
satkannanab (07-29-2008)
Hi..
Thanks for your kind reply.
I need to validate some conditions .
They are...1.not to be empty field,2.Only numerical,3.Fixed decimal of 4 digits only. These were the validation i have to do.
is it some_name should be text box name or wat?.return val_many(this, 'some_name');">
Thanks in advance,
regards,
satheesh kannan
I'm not clear on 3:
Would:Fixed decimal of 4 digits only
1
be OK?
How about:
1.352
?
What would be an example of the smallest number allowed? The largest? Is it that if decimals are used, only 4 places are allowed, or are 4 decimal places required?
To answer your question, yes. You would replacesome_namewith the name of your text fields.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
satkannanab (07-29-2008)
3. point is to fixed maximum number of 4 digits only e.g: 1234
No fraction s are allowed like 1.234.
satheesh
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function val_many(f, n){ for (var e = f.elements, i = e.length - 1; i > -1; --i) if (e[i].type && e[i].type == 'text' && e[i].name && e[i].name == n && (e[i].value == '' || isNaN(e[i].value - 0) || /\./.test(e[i].value) || e[i].value > 9999)){ alert('Some Message'); e[i].focus(); return false; } return true; } </script> </head> <body> <form action="#" onsubmit="return val_many(this, 'some_name');"> <input type="text" name="some_name"><br> <input type="text" name="some_name"><br> <input type="text" name="some_name"><br> <input type="text" name="some_name"><br> <input type="submit" value="Go!"> </form> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
satkannanab (07-29-2008)
Hi......
Thanks for ur kind and wonderful reply.
Its alerting when the function encounters a problem,but after clicking ok
in alert box the page getting load to next page.Its not focussing to the corresponding text box.
I think the function is returning but not returning false;
Waiting for ur reply,
regards,
satheesh kannan
Thanks yar...
Its working fine.i just taken out thethis code.Code:e[i].focus();
But again i have a small problem.some text boxes are disabled in the same name.
If i filled out correctly for all enabled text box,its being alerting for disabled text box too.HOw i can cure this too.
Regards,
satheesh kannan
Here (addition red):
Code:if (e[i].type && e[i].type == 'text' && e[i].name && e[i].name == n && !e[i].disabled && (e[i].value == '' || isNaN(e[i].value - 0) || /\./.test(e[i].value) || e[i].value > 9999)){
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Hi......
Its alerting for all text boxes if its enabled or disabled.If i filled out all text boxs also it alerting the message.
Waiting for ur reply,
regards,
satheesh kannan
Bookmarks