Dynamic links and Column value substitution of Text with special characters

[ad_1]

Hi Peter, thank you for your very useful plugin.

I’m hoping you can help with an issue I am having with dynamic links and column value substitution.

My issue is that one of the columns in the table contains text. I wish to pass that text as a variable to a javascript function which is called onclick.
this works fine for plain text but fails if the text contains a single quote (‘). There are other special characters which may also cause failure of the the parameter to be passed to javascript.

I have tried a number of workarounds but I have failed to find something that works.

Note that I have removed the “a” tag elements because they get interpreted as html in the post.

Here my dynamic hyperlink

onclick=”doOnlineTitleEdit($$ID$$,’$$online_title$$’)” class=”dashicons dashicons-edit”

Here is the value of the online_title in the database for the row: Don’t

Here the element which is generated by the plugin:

onclick=”doOnlineTitleEdit(27,’Don’t’)” class=”dashicons dashicons-edit”

The quote cause a problem in parsing the javascript.

I then tried to change the dynamic hyperlink to wrap the variable in double quotes instead of single quotes and set the onclick value using single quotes.

t looks like this:

onclick=’doOnlineTitleEdit($$ID$$,”$$online_title$$”)’ class=”dashicons dashicons-edit”

The element generated by the plugin is this:

onclick=”‘doOnlineTitleEdit(27,”Don’t”)’” class=”dashicons dashicons-edit”

It appears that the plugin has inserted double quotes and made some html character substitutions. In any case this link obviously will not work.

Lastly I have tried to change what is stored in the database to text which is html encoded:

For this dynamic hyperlink:

onclick=”doOnlineTitleEdit($$ID$$,’$$online_title$$’)” class=”dashicons dashicons-edit”

I have set the value of the online_title in the database for the row replacing the quote with the HTML encoding of Ampersand #39;

The element generated by the plugin is this:

onclick=”doOnlineTitleEdit(27,’Don’t’)” class=”dashicons dashicons-edit”

This also doesn’t work because the plugin is decoding the value stored in the database and replacing it with a single quote.

Is there a way to make this work? Is there a way to suppress the substitution of HBML encoding/decoding in the column value substitution?

  • This reply was modified 23 hours, 34 minutes ago by sujanm.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer