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

problem solving needed -- radio object

Tom
I have a problem, to which I have been unable to find a solution for
days now, after checking numerous references (both in books and
online). Perhaps someone here can help. Here's my problem:

I'm trying to define a series of radio objects as a large array for a
survey, like this:

1) Does this make sense?
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No

2) How about this?
<input type="radio" name="question[1]" value="Maybe"> Maybe
<input type="radio" name="question[1]" value="You're crazy"> You're
crazy

Now, when I try to access this object through javascript's DOM, I get
undefined across the board. Every other form object can be defined in
this manner, but because javascript automatically makes the radio
object an array (for each option), it seems unable to define the object
this way. I would have thought that it would define each object as a
two-dimensional array, i.e.:

document.form.question[0][0].value would be "Y";
document.form.question[0][1].value would be "N";
document.form.question[1][0].value would be "Maybe";
document.form.question[1][1].value would be "You're crazy";

and so forth...

I'm ready to scrap the whole idea in favor of a more dumbed-down
version, but if there's a way to make this work i'd prefer it much
more. Even if it doesn't work, I'd like to find a definitive answer
one way or the other!!!!

Thanks,

Nov 23 '05 #1
6 1525
Tom wrote on 14 nov 2005 in comp.lang.javascript:
1) Does this make sense?
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No


No the name has to be a simple string, it is not Javascript.

name="question0" is allowed

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #2
Evertjan. wrote:
Tom wrote on 14 nov 2005 in comp.lang.javascript:
1) Does this make sense?
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No

No the name has to be a simple string, it is not Javascript.
name="question0" is allowed


On the contrary, "question[0]" is allowed. It's just not always convenient,
and not allowed as an ID.
See http://www.jibbering.com/faq/#FAQ4_25

and also referred to in:
http://www.JavascriptToolbox.com/bestpractices/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 23 '05 #3
Tom a écrit :
I have a problem, to which I have been unable to find a solution for
days now, after checking numerous references (both in books and
online). Perhaps someone here can help. Here's my problem:

I'm trying to define a series of radio objects as a large array for a
survey, like this:

1) Does this make sense?
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No

Elements of a named group of radio buttons are already array elements. So

<input type="radio" name="rdoQuestion1" value="Y"> Yes
<input type="radio" name="rdoQuestion1" value="N"> No
would make sense while what you seem to be trying to do does not.
And accessing these as name/value is simple enough:
document.forms["FormName"].rdoQuestion1.value
2) How about this?
<input type="radio" name="question[1]" value="Maybe"> Maybe
<input type="radio" name="question[1]" value="You're crazy"> You're
crazy

Now, when I try to access this object through javascript's DOM, I get
undefined across the board. Every other form object can be defined in
this manner, but because javascript automatically makes the radio
object an array (for each option), it seems unable to define the object
this way.
A group of radio buttons is an array: why do you need to make things
more complex? What is exactly the problem that you are experiencing with
your form?
I would have thought that it would define each object as a
two-dimensional array, i.e.:
Why? What's your real problem? What exactly are you trying to achieve?
Can you post an url where we could see a concrete example of what you
are trying to do?
document.form.question[0][0].value would be "Y";
document.form.question[0][1].value would be "N";
document.form.question[1][0].value would be "Maybe";
document.form.question[1][1].value would be "You're crazy";

and so forth...

I'm ready to scrap the whole idea in favor of a more dumbed-down
version, but if there's a way to make this work i'd prefer it much
more. Even if it doesn't work, I'd like to find a definitive answer
one way or the other!!!!

Thanks,


Gérard
--
remove blah to email me
Nov 23 '05 #4
Evertjan. said the following on 11/14/2005 12:22 PM:
Tom wrote on 14 nov 2005 in comp.lang.javascript:

1) Does this make sense?
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No
No the name has to be a simple string, it is not Javascript.


Nonsense. That is even covered in the FAQ.
<URL: http://www.jibbering.com/faq/#FAQ4_25 >
name="question0" is allowed


So is name="question[0]"

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #5
Randy Webb wrote on 15 nov 2005 in comp.lang.javascript:
Evertjan. said the following on 11/14/2005 12:22 PM:
Tom wrote on 14 nov 2005 in comp.lang.javascript:

1) Does this make sense?
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No

No the name has to be a simple string, it is not Javascript.


Nonsense. That is even covered in the FAQ.
<URL: http://www.jibbering.com/faq/#FAQ4_25 >
name="question0" is allowed


So is name="question[0]"


You are right, of cource, Randy and others, I was wrong.

"name=" can allow strange characters,
that can only be incorporated in JS using he FAQ4_25 trick.

However it not a JS arrayelement that is built, methinks.

FAQ4_25 does not cover that.

However it gives a base for this roundabout way:

================

<form id='f1'>
<input type="radio" name="question[0]" value="Y"> Yes
<input type="radio" name="question[0]" value="N"> No
</form>

<script type='text/javascript'>

var question = new Array();
question[0] = 'question[0]'
//question[1] = 'question[1]'

var n=0
var p=0
var f1=document.forms['f1']

alert(f1.elements[question[n]][p].value)

p=1
alert(f1.elements[question[n]][p].value)

</script>

IE & FF tested

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #6
Evertjan. wrote on 15 nov 2005 in comp.lang.javascript:
var question = new Array();
question[0] = 'question[0]'
//question[1] = 'question[1]'


or for high quantities:

var question = new Array();
for (var m=0;m<50;m++)
question[m] = 'question['+m+']'
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #7

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

Similar topics

2
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html...
8
by: Shock | last post by:
Hello everyone, I am having a problem with the program below. I have isolated the problem to the onclick event that is located throughout arrQuestions. The onclick event refers to a function...
2
by: Paul Thompson | last post by:
I am trying to use various javascript tools, all of which work in NN, to work in IE. Here's my latest annoyance. I get a list of all objects on a page using docContents =...
2
by: SenthilVel | last post by:
Hi i have radio buttons in my Page and i am able to see some starnge behaviour with those. 1st : DSN 2nd radio button: MSDE the above 2 are in collection.
8
by: johnmmcparland | last post by:
Hi all, my program is trying to add group boxes with radio buttons at run time. While at one point it was able to draw the group boxes without the radio buttons, now it encounters problems just...
3
by: itissandeep | last post by:
I have a simple application that has a map. The user has to select two sets from a single type of feature from the map. I use two radio buttons under same GroupName for each set. When the page...
1
by: Prabhua | last post by:
Can anyone help me out in solving this problem. i am passing a value i.e., Path, from radio button in asp function to javascript function.But while printing the value only words are seen and...
1
by: Suma | last post by:
Hi, i have a problem with the controls .i have to validate Form1 Radio button option is checked or Not in the Form2. even after checking the radio button also in FOrm2 it is always taking as...
4
by: Z.K. | last post by:
I started a forms application and I put on the form three buttons. In the functions for the radio buttons I put in a single messagebox like: MessageBox("Hello 1") MessageBox("Hello 2") ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.