473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

problem in validating checkboxes

149 100+
hi,
in my project i used jsp form..if i enter the values it should be added in XML file..i used check boxes in my form..if i select more than one it is not updating in the XML file...can anyone help me out...here is the code...

Expand|Select|Wrap|Line Numbers
  1.  
  2. test.form
  3.  
  4. <input type="checkbox" name="colors[]" value="blue" id="blue">Blue <br>
  5. <input type="checkbox" name="colors[]" value="red" id="red">red <br>
  6. <input type="checkbox" name="colors[]" value="green" id="green">green <br>
  7.  
  8.  
Expand|Select|Wrap|Line Numbers
  1. function validate()
  2. {
  3. var chks = document.getElementsByName('colors[]');
  4. var hasChecked = false;
  5. for (var i = 0; i < chks.length; i++)
  6. {
  7. if (chks[i].checked)
  8. {
  9. hasChecked = true;
  10. break;
  11. }
  12. }
  13. if (hasChecked == false)
  14. {
  15. alert("Please select at least one.");
  16. return false;
  17. }
  18. return true;
  19. }
  20.  
thanks in advance,
madhu.
Jul 1 '10 #1
2 1151
Dormilich
8,658 Expert Mod 8TB
if i enter the values it should be added in XML file
I don’t see, where you do that. you have posted a validation function, that tells, whether no checkbox is checked ot not.
Jul 1 '10 #2
madhuriks
149 100+
hi,
i got the answer...
Jul 1 '10 #3

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

Similar topics

1
by: Peter B. Ensch | last post by:
Can anyone explain why this code fails when the set of checkboxes consists of only one. myForm.update.length returns 0 instead of 1 with the result that I get an alert box even tho' the one...
12
by: Torbjørn Pettersen | last post by:
I'm having problems validating my HTML code because of some ASP code I'm using: ---Start Code--- <% If rs("Average") = 0 Then VotingImage = "<img src="/images/0.gif" alt='No votes yet'>"...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
1
by: Miguel Orrego | last post by:
Hi, I have a form that is created dynamically from a recordset, this creates a line for each record together with 2 checkboxes, Yes & No so the source output would be something like this: ...
1
by: kannadasan | last post by:
Hi all I am using Datagrid where i place checkboxes in one column with some other columns.The purpose is, if i select the checkboxes and clicks the submit buton Email has to go to the selected...
8
by: David C. Stone | last post by:
I'm stuck trying to validate an html 4.01 page that uses an image map. I copied the second client-side example from here: <http://www.w3.org/TR/html401/struct/objects.html#h-13.6> and...
1
by: DFDavis | last post by:
I know this probably isn't the best way to code this but I have to take in a group of members for a company, generate a web page with their names, what measures they meet and then place a check box...
0
by: elkidos | last post by:
Hi there, I have a ListView control in my form with the CheckBoxes property set to True. The problem is, when I double-click on a line, the checkbox of the line become checked automatically....
7
by: mc | last post by:
I've not been able to get a Check box to client side validated on postback. with my changes I can get it to work on the serverside ok but not on the client. I have created a new control as...
1
mickey0
by: mickey0 | last post by:
hello, validating this file on w3c I have many error: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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...
0
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,...

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.