I have multiple checkboxes that I'll
be using and everytime I change the value of one of them, it makes the value of all the
other ones false. The only thing I could think of is that when the value gets changed
and sent to validate.php, it also looks for the other values and sets accordingly. If
that is the case, how could I make it so that only the intended value gets
changed.
JavaScript/JQuery Code Snippet (There
is a change function for each
variable):
$( document
).ready(function() {
var music =
document.getElementsByName("music_status");
var music_value =
document.getElementsByName("music_status")[0].value;
var rules =
document.getElementsByName("rules_status");
var rules_value =
document.getElementsByName("rules_status")[0].value;
var serverinfo =
document.getElementsByName("serverinfo_status");
var serverinfo_value =
document.getElementsByName("serverinfo_status")[0].value;
var module1 =
document.getElementsByName("module1_status");
var module1_value =
document.getElementsByName("module1_status")[0].value;
var module2 =
document.getElementsByName("module2_status");
var module2_value =
document.getElementsByName("module2_status")[0].value;
var module3
= document.getElementsByName("module3_status");
var module3_value =
document.getElementsByName("module3_status")[0].value;
$(music).change(function() {
if ($(music_value).val() == 'false')
{
$(music).val('true');
} else {
$(music).val('false');
}
window.location.href =
'validate.php?music_status=' + music_value;
})
$(rules).change(function() {
if
($(rules_value).val() == 'false') {
$(rules).val('true');
} else
{
$(rules).val('false');
}
window.location.href =
'validate.php?rules_status=' + rules_value;
})
});
HTML
Code Snippet (Have more of the checkboxes with the name and variable names
changed):
type="checkbox" name="music_status" id="cmn-toggle-1" class="cmn-toggle
cmn-toggle-round-flat" value="" ($music_status == 'true') {?> checked >
for="cmn-toggle-1">
validate.php
Code:
if
(isset($_GET["music_status"]) && $_GET["music_status"] == 'false') {
$config -> SetVar("music_status", 'true', "Music Status");
} else
{
$config -> SetVar("music_status", 'false', "Music
Status");
}
if (isset($_GET["rules_status"]) &&
$_GET["rules_status"] == 'false') {
$config -> SetVar("rules_status",
'true', "Rule Status");
} else {
$config ->
SetVar("rules_status", 'false', "Rule Status");
}
if
(isset($_GET["serverinfo_status"]) && $_GET["serverinfo_status"] == 'false')
{
$config -> SetVar("serverinfo_status", 'true', "Server Info
Status");
} else {
$config -> SetVar("serverinfo_status",
'false', "Server Info Status");
}
if
(isset($_GET["module1_status"]) && $_GET["module1_status"] == 'false')
{
$config -> SetVar("module1_status", 'true', "Module 1
Status");
} else {
$config -> SetVar("module1_status", 'false',
"Module 1 Status");
}
if (isset($_GET["module2_status"])
&& $_GET["module2_status"] == 'false') {
$config ->
SetVar("module2_status", 'true', "Module 2 Status");
} else {
$config -> SetVar("module2_status", 'false', "Module 2
Status");
}
if (isset($_GET["module3_status"])
&& $_GET["module3_status"] == 'false') {
$config ->
SetVar("module3_status", 'true', "Module 3 Status");
} else {
$config -> SetVar("module3_status", 'false', "Module 3
Status");
}
No comments:
Post a Comment