0

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.