Dynamic Variable name creation !!!

M

Mel

i have a form with say a bunch of check boxes with ID=CB1, ID=CB2,
etc.

when user clicks on any of the boxes, i would like to display a string

i do not want to write an if statement + switch for CB1...CBn
checkboxes. instead, i would like to create my ID's on the fly !!!
something like:

function toggle(k) {
var x = 'CB' + k
....
....
}
I KNOW above code does not work, but can you help pleeeeeeeeeeeeeeez
!!!

'er newbeeee scripter

Mel
 
K

kaeli

i have a form with say a bunch of check boxes with ID=CB1, ID=CB2,
etc.

You should also name them if you haven't. Some server-side scripting
languages need it and some browsers still need it.
when user clicks on any of the boxes, i would like to display a string

Um, what kind of string?
Do you care if the checkbox is checked?

<form name="f1" ...
<input type="checkbox" name="CB1" ... onClick="toggle(this)"

function toggle(k) {
var x = 'CB' + k

Now this looks like you're dynamically creating the boxes.

What are you trying to do? Create new boxes or access the name of the box the
user clicked?
If you just want the name, do
var x = k.name;
assuming you pass it like I did above.
If you want the id, do
var x = k.id;

--
--
~kaeli~
She was engaged to a boyfriend with a wooden leg but broke
it off.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
M

Michael Winter

You should also name them if you haven't. Some server-side scripting
languages need it and some browsers still need it.

If you plan on submitting the form, *need* is the right word. Can't submit
without a name...

[snip]

Mike
 
M

Michael Winter

enlightened us with...
[snip]
If you plan on submitting the form, *need* is the right word. Can't
submit without a name...

I know that's true for the form, but is it also true for the elements? I
thought it was, but I didn't want to say that and be wrong.

A FORM element doesn't need either a name or an id unless you plan to use
the forms collection or target it with fragment identifier (id only).

If you plan to submit data through a form, you *must* have a name set for
the elements (controls) being sent. They cannot be successful otherwise.
Like forms, an id is only useful for referencing or fragment id targeting.

Mike
 
K

kaeli

A FORM element doesn't need either a name or an id unless you plan to use
the forms collection or target it with fragment identifier (id only).

If you plan to submit data through a form, you *must* have a name set for
the elements (controls) being sent. They cannot be successful otherwise.
Like forms, an id is only useful for referencing or fragment id targeting.

Thanks for the clarification.
I read the same thing here, but it wasn't in English. ;)

http://www.w3.org/TR/html401/interact/forms.html#form-controls
JIC anyone cares to look at the specs. I have comprehension problems with
them myself.

--
--
~kaeli~
Not one shred of evidence supports the notion that life is
serious.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top