Title: checkbox name i need in text field
Tags: javascript;jquery;html;checkbox
Question: <input type="checkbox" name="checkbox" id="checkbox1" value="10" /&gt; Value 1
<input type="checkbox" name="checkbox" id="checkbox2" value="20" /&gt; value 2
<input type="checkbox" name="checkbox" id="checkbox3" value="30" /&gt; value 3
<input type="checkbox" name="checkbox" id="checkbox4" value="40" /&gt; value 4
<input type="checkbox" name="checkbox" id="checkbox5" value="50" /&gt; value 5
Ect, etc. I want the add value of selected checkboxes in a text field and all selected checkbox value in a diffrent diffrent checkboxes.
Using this code for the adding of checkboxes but dont know how to get the name of the check box as well as dynamic. For example value 1 , value 2, value 3 in a textbox in front of checkbox in a hidden form.
Code of adding is given below.
$(document).ready(function () {
$("#textfield2").val( $("#textfield").val());
$('.priceAdded input[type="checkbox"]').on("change", function () {
var priceAdded = $("#textfield").val();
$('.priceAdded input[type="checkbox"]').each(function () {
if ($(this).is(":checked")) {
priceAdded = parseFloat(priceAdded) + parseFloat($(this).val());
}
$("#textfield2").val(priceAdded);
});
});
return false;
Comment: are you able to get the value 1 in a textbox after checking it and in another box its value.

Comment: Do you have a jsfiddle of your code so we can see the big picture? It's not quite clear what you're looking for just from the code.

Comment: I dont' fully understand what your question is, but you can probably read the attributes of the checkbox on the $(this) object inside your loop.

Here is the accepted answer: If you're wanting to get the id of the checkboxes and a total of the selected values
http://jsfiddle.net/hb0hhbk4/1/
<input type="checkbox" name="checkbox" id="checkbox1" value="10" class='sum' /&gt;Value 1
<input type="checkbox" name="checkbox" id="checkbox2" value="20" class='sum' /&gt;value 2
<input type="checkbox" name="checkbox" id="checkbox3" value="30" class='sum' /&gt;value 3
<input type="checkbox" name="checkbox" id="checkbox4" value="40" class='sum' /&gt;value 4
<input type="checkbox" name="checkbox" id="checkbox5" value="50" class='sum' /&gt;value 5
<input id='textfield1' type='text' /&gt;
<input id='textfield2' type='text' /&gt;
$("input[type='checkbox'].sum").on('click', function () {
var total = 0;
var ids = [];
$("input[type='checkbox'].sum:checked").each(function () {
var value = parseInt($(this).val());
total += value;
ids.push($(this).attr('id'));
});
ids = ids.join(" ", ids);
$('#textfield1').val(ids);
$('#textfield2').val(total);
Comment for this answer: Its working but i need a bit change in it. total is great and i want textboxes infront of every checkbox and when some one check it its id come in it as u had join ids in one textbox.
Comment for this answer: Can you make a picture of what you are describing?

Here is another answer: If you're looking for the LABEL near the checkbox, you need to do something like this
<span&gt;<input type="checkbox" name="checkbox" id="checkbox1" value="10" /&gt; Value 1</span&gt;
<span&gt;<input type="checkbox" name="checkbox" id="checkbox2" value="20" /&gt; value 2</span&gt;
<span&gt;<input type="checkbox" name="checkbox" id="checkbox3" value="30" /&gt; value 3</span&gt;
<span&gt;<input type="checkbox" name="checkbox" id="checkbox4" value="40" /&gt; value 4</span&gt;
<span&gt;<input type="checkbox" name="checkbox" id="checkbox5" value="50" /&gt; value 5</span&gt;
And inside the each function you can access the label with
$( this ).closest( "span" ).text();

Here is another answer: Using that layout, you probably won't be able to, because there's no way of isolating "value 1", for example, from the rest of the code (it isn't the content of an element, or an attribute of anything.
You could put the "Value 1/2/3/4" text in something like a span and then you can use the adjacent selector in Jquery. for exampl75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0
<input type="checkbox" name="checkbox" id="checkbox1" value="10" /&gt; <span&gt;Value 1</span&gt;
Then use
$(this).next().text();
To get the contents of the span directly after the checkbox that's just been clicked.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:11/19/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery><html><checkbox>', 'Title': 'checkbox name i need in text field', 'ViewCount': 563, 'id': 33808146, 'user_AboutMe': None, 'user_AccountId': 5505484.0, 'user_DisplayName': 'Harsimran singh', 'user_Reputation': 95.0, 'user_Views': 34.0, 'user_id': 4373440.0}}