views:

112

answers:

2

I need to access to a value in a checkbox, the atribute value has content, so i need to place the id somewhere else i created a label, but i have not access to that value

alert(check[i].label); // doesnt work 

where else can i place a value in checkbox. Please dont write that i can do this

  <input type='checkbox' id='bla' name='mybla' vlaue='myvalue'> Hy

Where can i place some other values ?

I tryed with this

<input type='checkbox' id='bla' name='mybla' vlaue='myvalue' label='myothervalue'> Hy

first i get all checkbox ect... and in the for loop i did this

alert(check[i].label); // doesnt work 

How can i do that?

+4  A: 

It is indeed possible to store the extra data as a custom attribute on the <input> element. When you want to read the value, you can do it like this:

alert(check[i].getAttribute('label'));

Since you have tagged the question jQuery, here's the trendy version:

alert($(check[1]).attr('label'));

See these discussions if you are woried about using custom HTML attributes.

Jørn Schou-Rode
Thanks for your answer
streetparade
A: 

When I am being tempted to do this, I prefer to use a related hidden element to store the "other value". It feels cleaner to me, and I also don't have to wade through the validation warnings that otherwise could come at me.
Is that something you can use here?

npup