Using jQuery to add tick box values to a hidden field - javascript

I am trying to collect tick box values and assign the ticked boxes values to a hidden field so that I can save all of the ticked boxes values into one column in a comma delimited format, instead of many.
How could I go about doing that?
Thanx in advance!

You can use the map and join function like this:
var vals = $(':checkbox:checked').map(function(){
return $(this).val();
}).get().join(',');
// save the values to a hidden field
$('#hidden_id').val(vals);

Related

Selecting values from multiple select option box - Jquery

I am trying to select values in a multiple select option box. When i run my current code below, no item is selected in the option box but when i do parseInt(value) it only selects just the first option.
When i console.log(selected), it returns 4,5. How can insert 4,5 into $("#edit-items") to make it select both values in the option box.
PS: Sorry for my english
JS
var selected = $(this).attr('data-items'); returns 4,5
items = parseInt(selected)
$("#edit-items").val([items]);
parseInt() will only parse the first integer from 4,5. If you want to get all the intgers as an array, split the string and call parseInt() on each array element.
items = selected.split(',').map(str => parseInt(str));
$("#edit-items").val(items);

how to split a string and fill a dynamic table with the values inside that string in adobe livecycle?

I have a text that is a combination of values separated with commas "," and I want to split it and fill some column inside a table with those values.
I tried this code in the indexChange event of the table row:
var raw = this.EXTKD.rawValue.split(',');
this.EXTKD.rawValue = raw[this.index];
knowing that EXTKD is the name of the cell that I want to fill with the value, and it is intially filled with the whole text that I want to split.
when I try the above code only the first row gets filled.
I simply created another edit text called EXTKDraw to hold the raw value and hide it from the form view and I just modified my code to be called in the ondocready event like this:
var raw = EXTKDraw.rawValue.split(',');
this.EXTKD.rawValue = raw[this.parent.index];
where this.parent.index represents the index of the row of the table.

Get selected check boxes values from table using Java script

I was using select Person_name = $('#selectedPerson').val()
person_name.length is showing 2 if selected 2 values.
Now i have changed to check boxes which is in table. If i am using person_name= document.getElementById("selectedPerson").innerText, person_name.length is not working. It is taking length of the content. I want to count of the person and it is value which i am selecting in check-boxes.
Thanks,
Raja.
Side note: an ID should only ever be applied to one element, so you want .selectedPerson not #selectedPerson if it's going to select two things.
var people = $('.selectedPerson');
var count = people.count;
var name = people.text();

Save select values in an array and go through it

I have 6 select fields to select three different options ("Please Select..", "Yes" and "No"). I want to be able to know which values has been selected inside a group, each group of select is inside a div. I try using this:
$('#qqq').find('select').change(function () {
// alert($(this).val());
var option = $(this).val();
selectValues.push($(this).val());
But this only works when you change the value, and donĀ“t storage the values, therefore if you go through the group in other order the results are different. For example if you start in the last select and then go in inverse order. Pushing the values into a variable, the values are saved but if you change twice is saved it twice in "selectValues"
My html is something like this:
<div class="mygroup">
<select id="aa">
<select id="bb">
<select id="cc">
</div>
The values of the select are generated in jQuery, therefore the values can be retrieve using --> this.val()
My question is how can I retrieve the values of a group and then go through it? I had though in save it in an array and then go through it, but I don't know if the array values are going to change when you change the select twice.
I want to know it, because if any of the select is "Yes", some below input fields should be required and if all of them are "No", those fields should be readonly.
Like this:
var curVals = {};
$('#qqq').find('select').each(function () {
curVals[$(this).prop('id')] = $(this).val();
});
or this:
var $selectedYes = $('#qqq').find('select').filter(function () {
return $(this).val().toLowerCase() === 'yes';
});
If any have 'Yes' then $selectedYes will be a jQuery object containing only those select element(s); if none are, it will be an empty jQuery object.

How to insert selected element from multiple selection into an input?

hi everyone i have a problem.
i have a multiple selection and i want to select something and put it into an input through a button i hope i have been clear :
i manage to get the select item with this jquery code :
var chosen= $('#droite option:selected').val();
droite is an id for the multiple selection
and i want to put it into the input wich has an id : chosen item here is my jquery code:
$("#chosenitem").prepend(chosen);
and it won't work do you have any idea why .?
You need to call val() on the select itself, not the options it contains:
var chosen = $('#droite').val();
Similarly, to set the value of the #chosenitem input, use val() with a parameter:
$("#chosenitem").val(chosen);
Note that if multiple options are selected in the #droite element, the value returned will be a comma delimited string, eg. foo,bar,baz.
You should call val() to set the value of #chosenitem
$("#chosenitem").val(chosen);

Categories

Resources