473,405 Members | 2,262 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,405 software developers and data experts.

Validation with javascript 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 Code:

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

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

Code:

function check(form) { a=0; for (i=0;i<form.question[1].length;i++){ if
(form.question[1][i].checked===true) {a=1;} } if (a==0) {
alert("question[1] no.1: You didn't answer the question"); return
false; } }
Everything was working 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 2295
ka*********@gmail.com wrote:
In html i have some question, and the answers are radio
buttons ... the names of variables in html are array ...
There are no arrays in HTML, it is a mark-up language not a programming
language. The value of a NAME attribute is just a sequence of
characters, with no additional meaning.
like question[1], question[2] ... etc.
and every question has multiple value, depending of
the answer.

HTML Code:

<form action="thx.php" method=POST name=form onSubmit="return
check(this)">
There are no <INPUT type="radio"controls here.
In javascript i have to determinate if the question is
answered, if it is not then return false ...

Code:

function check(form) { a=0; for (i=0;i<form.question[1].length;i++){
if (form.question[1][i].checked===true) {a=1;} } if (a==0) {
In javascript the code - question[1] - is meaningful, it is a bracket
notation property accessor. As the character sequence 'question[1]' had
no meaning in HTML there is nothing in the DOM that makes sense to
javascript's understanding of the property accessor. However, there is a
property of the form's - elements - collection that has the name
'questions[1]' and it can be referenced by name as:-

form.elements["question[1]"]

See:-

<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >
alert("question[1] no.1: You didn't answer the question"); return
false; } }
Everything was working fine until i changed my variables into
arrays. What is wrong now?
You changed the name from a sequence of characters that could be a
javascript Identifier, and so could be used in a dot notation property
accessor, into a sequence of characters that resembled a bracket
notation property accessor, and so had very different meaning when
inserted into a dot-notation property accessor.
How javascript handle two dimensional array?
That is irrelevant as the subject of your question is a Collection not
an array, and it remains one dimensional.

Richard.
Dec 20 '06 #2
Lee
ka*********@gmail.com said:
>
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.
Read the newsgroup FAQ, particularly:
http://www.jibbering.com/faq/#FAQ4_25
--

Dec 20 '06 #3
thank you very very much :))
it works now :)

Richard Cornford wrote:
ka*********@gmail.com wrote:
In html i have some question, and the answers are radio
buttons ... the names of variables in html are array ...

There are no arrays in HTML, it is a mark-up language not a programming
language. The value of a NAME attribute is just a sequence of
characters, with no additional meaning.
like question[1], question[2] ... etc.
and every question has multiple value, depending of
the answer.

HTML Code:

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

There are no <INPUT type="radio"controls here.
In javascript i have to determinate if the question is
answered, if it is not then return false ...

Code:

function check(form) { a=0; for (i=0;i<form.question[1].length;i++){
if (form.question[1][i].checked===true) {a=1;} } if (a==0) {

In javascript the code - question[1] - is meaningful, it is a bracket
notation property accessor. As the character sequence 'question[1]' had
no meaning in HTML there is nothing in the DOM that makes sense to
javascript's understanding of the property accessor. However, there is a
property of the form's - elements - collection that has the name
'questions[1]' and it can be referenced by name as:-

form.elements["question[1]"]

See:-

<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >
alert("question[1] no.1: You didn't answer the question"); return
false; } }
Everything was working fine until i changed my variables into
arrays. What is wrong now?

You changed the name from a sequence of characters that could be a
javascript Identifier, and so could be used in a dot notation property
accessor, into a sequence of characters that resembled a bracket
notation property accessor, and so had very different meaning when
inserted into a dot-notation property accessor.
How javascript handle two dimensional array?

That is irrelevant as the subject of your question is a Collection not
an array, and it remains one dimensional.

Richard.
Dec 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: EviL KerneL | last post by:
Hi - I am trying to figure out a way to enforce the validation included for this form based on whether the user chooses "email" or "phone" as the contact choice. Right now it is set to enforce...
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>...
3
by: Gary Varga | last post by:
In the file WebUIValidation.js, when a postback that doesn't fail the validation has a javascript error saying summary is undefined in the ValidationSummaryOnSubmit function....
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
10
by: hardik | last post by:
how i can set 3*3 array in javascript i have tried this but didnt work <Script> var a=new array() <\Script> but it didnt work.
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
3
by: kaarmen | 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 of...
2
by: wgarner | last post by:
I am trying to implement a two-dimensional recursive formula, g(x,y). It is sort of like multiplication. g(x,y) = 0 if either x or y is 0. g(1, y) = y and g(x, 1) = x. Those are the base...
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: 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:
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.