Check checkbox whose values are stored in an array
Date : March 29 2020, 07:55 AM
wish of those help Use attribute-value selector as follow var preSelected = ['module-001', 'module-003', 'module-027'];
var selector = ':checkbox[value="' + preSelected.join('"], :checkbox[value="') + '"]';
$(selector).prop('checked', true);
:checkbox[value="module-001"], :checkbox[value="module-003"], :checkbox[value="module-027"]
var vowels = ['a', 'e', 'i', 'o', 'u'];
var selector = ':checkbox[value="' + vowels.join('"], :checkbox[value="') + '"]';
console.log(selector);
$(selector).prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" name="aa" value="a" /> A
<input type="checkbox" name="bb" value="b" /> B
<input type="checkbox" name="Cc" value="c" /> C
<input type="checkbox" name="dd" value="d" /> D
<input type="checkbox" name="ee" value="e" /> E
<input type="checkbox" name="ff" value="f" /> F
<input type="checkbox" name="ii" value="i" /> I
|
stored checkbox values fetch and keep checkbox selected
Tag : php , By : user171555
Date : March 29 2020, 07:55 AM
Hope this helps Simple use IN_ARRAY = (in_array($rtg['tagName'],$tg1))? 'checked="checked"' : "" ?> $tg = $row['tagpost'];
$tg1 = explode(',', $tg);
..........
foreach($rt as $rtg){
?>
<input type="checkbox" name="postTag[]" value="<?php echo $rtg['tagurl']; ?>" <?php if(in_array($rtg['tagurl'],$tg1)){ echo 'checked="checked"'; } ?> > <?php echo $rtg['tagName']; ?>
<?php
}
|
How to output responses based on checkbox values stored in an array?
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have persistent checkboxes which represent the days of the week. I was able to store these values in localStorage in an array so that they stay after refresh. , I hope you mean something like this //checkbox
//function for persistent checkbox
var formValues = JSON.parse(localStorage.getItem('formValues')) || {};
var $checkboxes = $("#checkbox-wrapper :checkbox");
function outputResult(isWeekday,isWeekend){
var output = ""
if( isWeekday && isWeekend ) output = "Both";
else if( isWeekday ) output = "Weekday";
else if( isWeekend ) output = "Weekend";
document.getElementById("output").innerHTML = output;
}
function checkDay(){
var isWeekday = false;
var isWeekend = false;
$checkboxes.each(function(){
if( this.checked ){
if( this.id == "saturday" || this.id == "sunday" ) isWeekend = true;
else isWeekday = true;
}
});
outputResult(isWeekday,isWeekend);
}
function updateStorage(){
$checkboxes.each(function(){
formValues[this.id] = this.checked;
});
localStorage.setItem("formValues", JSON.stringify(formValues));
checkDay();
}
$checkboxes.on("change", function(){
updateStorage();
});
// On page load
$.each(formValues, function(key, value) {
$("#" + key).prop('checked', value);
});
|
How to pass down checkbox values from an iterating table row to an Array in Vue?
Tag : arrays , By : Kristian Hofslaeter
Date : March 29 2020, 07:55 AM
To fix this issue values in your tableBody component is local data, it will not be share between row. I saw you want to save data to vuex, you might want to implement as below: <template>
<tr>
<td>{{id}}</td>
<td>{{indId}}</td>
<td><input type="checkbox" :value="id" :checked="isSelected" @click="toggleValue">...</td>
</tr>
</template>
<script>
import { mapActions, mapState } from 'vuex'
export default {
props: {
id: {
type: String,
reuired: true
},
indId: {
type: String,
reuired: true
},
methods: {
...mapActions([
'selectValues',
'deselectValues'
]),
toggleValue() {
if (!this.isSelected) {
this.selectValues(this.id)
} else {
this.deselectValues(this.id)
}
}
},
computed: {
...mapState(['selectedValues']),
isSelected () {
return this.selectedValues && this.selectedValues.includes(this.id)
}
}
</script>
selectValues(state, payload){
state.selectedValues = state.selectedValues.concat([payload])
}
deselectValues (state, payload) {
state.selectedValues = state.selectedValues.filter(item => item !== payload)
}
|
About to store multiple values of child checkbox related to parent checkbox, data is stored only one time
Tag : php , By : n1ckless_id
Date : March 29 2020, 07:55 AM
it fixes the issue When I store services and activity then services and activity value store multiple times in the database, I also use implode instead of foreach but that time first service and first activity stored, the following image describes the idea about what I exactly want. HTML:-<form method='post' id='userform' action='sh.php'> <tr>
<td>Trouble Type</td>
<br>
<td>
<input type='checkbox' name="arr[1][service]" value='1'>tds<br> <br>
<input type='checkbox' name="arr[1][activity][]" value='1'>Return<br>
<input type='checkbox' name="arr[1][activity][]" value='2'>Filling<br>
<br>
<input type='checkbox' name="arr[2][service]" value='2'>Gst<br> <br>
<td>
<input type='checkbox' name="arr[2][activity][]" value='1'>Return<br>
<input type='checkbox' name="arr[2][activity][]" value='2'>Filling<br>
<br>
<input type='checkbox' name="arr[3][service]" value='3'>vat<br> <br>
<td>
<input type='checkbox' name="arr[3][activity][]" value='1'>Return<br>
<input type='checkbox' name="arr[3][activity][]" value='2'>Filling<br>
<br>
</td> </tr> </table> <input type='submit' name="submit" class='buttons'>
PHP:-<?php
if(isset($_POST['submit']))
{
foreach ($_POST['arr'] as $input) {
foreach ($input['activity'] as $activity) {
$servicevalue = $input['service'];
$query = "insert into serviceacitivitymap(service_id,activity_id)
values('$servicevalue','$activity')";
$insert_row=$conn->query($query) or die ($conn->error.__LINE__);
echo $query;
echo "<br>";
}
}
}
|