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.