473,385 Members | 1,752 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,385 software developers and data experts.

Validation with js of two dimensional array

In html i have some question, and the answers are radio buttons ...
the names of variables in html are array ... like question[1], question[2] ... etc.
and every question has multiple value, depending of the answer.


[HTML]<form action="thx.php" method=POST name=form onSubmit="return check(this)">[/HTML]


In javascript i have to determinate if the question is answered, if it is not then return false ...

Expand|Select|Wrap|Line Numbers
  1. function check(form) {
  2.  
  3.  
  4.     a=0;
  5.     for (i=0;i<form.question[1].length;i++){
  6.     if (form.question[1][i].checked===true)  {a=1;}
  7.     }
  8.     if (a==0) {
  9.     alert("question[1] no.1: You didn't answer the question");
  10.     return false;
  11.     }
  12. }
Everything work fine until i changed my variables into arrays.
What is wrong now?
How javascript handle two dimensional array?

pls help :)
Dec 20 '06 #1
3 1949
b1randon
171 Expert 100+
In html i have some question, and the answers are radio buttons ...
the names of variables in html are array ... like question[1], question[2] ... etc.
and every question has multiple value, depending of the answer.


[HTML]<form action="thx.php" method=POST name=form onSubmit="return check(this)">[/HTML]


In javascript i have to determinate if the question is answered, if it is not then return false ...

Expand|Select|Wrap|Line Numbers
  1. function check(form) {
  2.  
  3.  
  4.     a=0;
  5.     for (i=0;i<form.question[1].length;i++){
  6.     if (form.question[1][i].checked===true)  {a=1;}
  7.     }
  8.     if (a==0) {
  9.     alert("question[1] no.1: You didn't answer the question");
  10.     return false;
  11.     }
  12. }
Everything work fine until i changed my variables into arrays.
What is wrong now?
How javascript handle two dimensional array?

pls help :)
This is surely a problem
form.question[1][i].checked===true
You shouldn't have ===, just == :)
Dec 20 '06 #2
AricC
1,892 Expert 1GB
Here is some info on 2D arrays in javascript if you need some clarification.

HTH,
Aric
Dec 20 '06 #3
This is surely a problem You shouldn't have ===, just == :)

ups :)

but it doesn't work eider :(
Dec 20 '06 #4

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

Similar topics

7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
3
by: karmenkrile | last post by:
In html i have some question, and the answers are radio buttons ... the names of variables in html are array ... like question, question ... etc. and every question has multiple value, depending...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
5
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.