I put the following JS code in the JS Editor window in the view. But it does not work at all.
When this code is added directly in the header.php, it works. Why?
jQuery(function($){
//ページを読み込んだら、チェックボックスにクッキーの値を反映する
if($.cookie("chk_sample_selected_value")){
var load_values = $.cookie("chk_sample_selected_value").split(",");
for(var i = 0; i < load_values.length; ++i){
load_values[i] = decodeURIComponent(load_values[i]);
}
$("input[type=checkbox][name=chk_sample]").each(function(){
this.checked = $.inArray(this.value, load_values) != -1;
});
}
//チェックを変えたらクッキーを保存するイベントを登録する
$("input[type=checkbox][name=chk_sample]").change(function(){
var save_values = [];
$("input[type=checkbox][name=chk_sample]").each(function(){
this.checked && save_values.push(encodeURIComponent(this.value));
});
$.cookie("chk_sample_selected_value", save_values.join(","));
});
//▼現在のcookieの値を見る
$("#btn_show_cookie").click(function(){
$("#txt_cookie_value").val($.cookie("chk_sample_selected_value"));
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
Thank you for contacting our support forum.
It could be because of the load time of the script. Could you let me know what error is generated in the console when this is added to the view JS editor ?
Thanks,
Shane
I attached the screenshot.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
Would you mind providing me with access to the site that this issue is on?
As well as the content template that this is on as well ?
This way I can debug the issue better as it should work from what i see in your code.
Thanks,
SHane
The page I am engaging now is ...
hidden link
And please see the attached screenshot.
I am expecting the area surrounded in red line shall be working by JavaScript.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
When I try to log into the site, i'm getting the error 403 on the site.
Not sure what is causing this.
Try this.
jQuery( document ).ready(function() {
jQuery(function($){
//ページを読み込んだら、チェックボックスにクッキーの値を反映する
if($.cookie("chk_sample_selected_value")){
var load_values = $.cookie("chk_sample_selected_value").split(",");
for(var i = 0; i < load_values.length; ++i){
load_values[i] = decodeURIComponent(load_values[i]);
}
$("input[type=checkbox][name=chk_sample]").each(function(){
this.checked = $.inArray(this.value, load_values) != -1;
});
}
//チェックを変えたらクッキーを保存するイベントを登録する
$("input[type=checkbox][name=chk_sample]").change(function(){
var save_values = [];
$("input[type=checkbox][name=chk_sample]").each(function(){
this.checked && save_values.push(encodeURIComponent(this.value));
});
$.cookie("chk_sample_selected_value", save_values.join(","));
});
//▼現在のcookieの値を見る
$("#btn_show_cookie").click(function(){
$("#txt_cookie_value").val($.cookie("chk_sample_selected_value"));
});
Please let me know if this helps.
Thanks,
Shane
I checked the ID and Password I had sent you and I confirmed it was correct. Please try to login again.
Then I tried the code you sent, but it did not work.
I am waiting for your next reply.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
Still no luck.
Clicking the link produces the same result.
However I did an entire check of your code block and found that it was missing a clicking });
jQuery(function($){
//ページを読み込んだら、チェックボックスにクッキーの値を反映する
if($.cookie("chk_sample_selected_value")){
var load_values = $.cookie("chk_sample_selected_value").split(",");
for(var i = 0; i < load_values.length; ++i){
load_values[i] = decodeURIComponent(load_values[i]);
}
$("input[type=checkbox][name=chk_sample]").each(function(){
this.checked = $.inArray(this.value, load_values) != -1;
});
}
//チェックを変えたらクッキーを保存するイベントを登録する
$("input[type=checkbox][name=chk_sample]").change(function(){
var save_values = [];
$("input[type=checkbox][name=chk_sample]").each(function(){
this.checked && save_values.push(encodeURIComponent(this.value));
});
$.cookie("chk_sample_selected_value", save_values.join(","));
});
//▼現在のcookieの値を見る
$("#btn_show_cookie").click(function(){
$("#txt_cookie_value").val($.cookie("chk_sample_selected_value"));
});
});
Please try this one now.
Thanks,
Shane
Please try to login from the following URL.
hidden link
ID and password are same.
Unfortunately, the code is not working.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hello,
Still getting the error 403.
Also if the code works in your header then you can allow it to stay there. Is there any particular reason why you want it to be added to this view?
Also please ensure that your server isn't blocking my IP.
Thanks,
Shane