user1212520 user1212520 - 14 days ago 5
jQuery Question

Assigning two values to a checkbox javascript

I need to pass two different values back as the result from one checkbox. I tried an object, but the result was undefined (the code works with one value).

' <input type="checkbox" id="cat" value="'+{value1:, value2:} +'"/>'

result.value1 is always undefined, whereas result works for just a string.

What is the best way to do this using javascript/jquery.


You can use attr for add more values, for example:

<input type="checkbox" id="cat" data-value1="blue" data-value2="red" value=""/>

Get values using jQuery, use:

$("#cat").data("value1");//return 'blue'
$("#cat").data("value2");//return 'red'