Skip Navigation

[Resolved] JS Editor

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 2 voices.

Last updated by Shane 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1130566

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"));

#1130723

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

#1131816
console.png

I attached the screenshot.

#1132077

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

#1132293

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.

#1132773

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2018-10-23 at 9.25.36 AM.png

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

#1133211

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.

#1133596

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

#1134128

Please try to login from the following URL.
hidden link

ID and password are same.

Unfortunately, the code is not working.

#1134344

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

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.