I have a html form, and i have also checkboxes in it. Values of checkboxes is coming from SQL-database via Web Api.
$(document).ready(function () {
var $MaterialName = $('#materiallist');
function addMaterials(material) {
$MaterialName.append('<input type="checkbox" >' + material.MaterialName + ' </input>');
}
<div class="form-group">
<label for="material" class="col-xs-3 control-label header">Käytetyt materiaalit</label>
<div class="col-xs-7">
<div class="checkbox" id="materiallist"></div>
</div>
</div>
I want to save those checked values to another SQL-database (named Form), along with the other input values in that form.
I haven't found a solution where all the other input fields also needs to be saved as well, only solutions where is only checkboxes and button. Also, my values are coming from a database, and are not "hard-coded" options.
I tried this:
function getCheckedMaterials() {
var materialArray = [];
$("#materiallist input:checked").each(function () {
materialArray.push($(this).val());
});
var selected;
selected = materialArray.join(',');
alert("You have selected " + selected);
}
This doesn't work as I need, because I can't get the values.
All these values from other input fields goes to the Form database when I press the #tallenna button. I need the checked values to be saved in MaterialName as text.
$('#tallenna').click(function () {
var form = {
FormFiller: $FormFiller.val(),
CustomerContact: $CustomerContact.val(),
ReadyToDate: $ReadyToDate.val(),
Instructions: $Instructions.val(),
Amount: $Amount.val(),
PcsAmount: $PcsAmount.val(),
ChargeFull: $ChargeFull.val(),
ChargeByPcs: $ChargeByPcs.val(),
FreightCost: $FreightCost.val(),
CustomerName: $CustomerName.val(),
WorkName: $WorkName.val(),
MaterialName: getCheckedMaterials // ????
};