snut8,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.value {
border: solid 1px rgba(255, 0, 0, 1);
width: 100px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
var inp = document.querySelector("#two") || $("<input>", {/*type : "hidden",*/ name : "test", id : "two"}).appendTo("body")[0];
$(".value").on("click", function() {
if($(this).is(".add")) return;
$(this).addClass("add");
var text = $.map($(".add"), $.text);
inp.value = text.join(" ");
})
});
</script>
</head>
<body>
<div class="value">1</div>
<div class="value">2</div>
<div class="value">3</div>
<div class="value">4</div>
</body>
</html>