<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>PHPOnlineSupport - Recent questions and answers in Javascript</title>
<link>http://phponlinesupport.com/qa/javascript</link>
<description>Powered by Portrave Solutions Pvt. Ltd.</description>
<item>
<title>Answered: json_encode Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data</title>
<link>http://phponlinesupport.com/433/jsonencode-uncaught-syntaxerror-unexpected-character-column?show=434#a434</link>
<description>That JSON is already parsed. You dont need to parse it again which will produce that error. Remove that line and it should work ok.</description>
<category>Javascript</category>
<guid isPermaLink="true">http://phponlinesupport.com/433/jsonencode-uncaught-syntaxerror-unexpected-character-column?show=434#a434</guid>
<pubDate>Thu, 03 Feb 2022 19:21:47 +0000</pubDate>
</item>
<item>
<title>Answered: Day.js date difference not working</title>
<link>http://phponlinesupport.com/431/day-js-date-difference-not-working?show=432#a432</link>
<description>In my experience, the day difference with format will not work. Its the same with moment.js and Day.js&lt;br /&gt;
&lt;br /&gt;
Try this&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var date1 = dayjs(field_data);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var date2 = dayjs();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var diff = date1.diff(date2, 'day');&lt;br /&gt;
&lt;br /&gt;
alert(diff);</description>
<category>Javascript</category>
<guid isPermaLink="true">http://phponlinesupport.com/431/day-js-date-difference-not-working?show=432#a432</guid>
<pubDate>Wed, 26 Jan 2022 21:34:31 +0000</pubDate>
</item>
<item>
<title>Answered: Find difference between two dates</title>
<link>http://phponlinesupport.com/429/find-difference-between-two-dates?show=430#a430</link>
<description>Yes, you can use Jquery calendar, Moment.js, Day.js etc&lt;br /&gt;
&lt;br /&gt;
I personanlly recommend the Day.js as its very lightweight&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script src=&amp;quot;&lt;a href=&quot;https://unpkg.com/dayjs@1.8.21/dayjs.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://unpkg.com/dayjs@1.8.21/dayjs.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/a&gt;&lt;br /&gt;
&amp;lt;script&amp;gt;dayjs().format()&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const date1 = dayjs('2019-01-25')&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const date2 = dayjs('2019-01-26')&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var diff = date1.diff(date2, 'day')</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/429/find-difference-between-two-dates?show=430#a430</guid>
<pubDate>Wed, 26 Jan 2022 20:53:36 +0000</pubDate>
</item>
<item>
<title>Answered: Dynamically add  textbox, input in html form using JavaScript.</title>
<link>http://phponlinesupport.com/359/dynamically-add-textbox-input-in-html-form-using-javascript?show=363#a363</link>
<description>

&lt;pre class=&quot;lang-js s-code-block hljs javascript&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 12px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: 1.30769; font-family: var(--ff-mono); font-size: 13px; vertical-align: baseline; box-sizing: inherit; width: auto; max-height: 600px; overflow: auto; background-color: var(--highlight-bg); border-radius: 5px; color: var(--highlight-color); overflow-wrap: normal;&quot;&gt;&lt;code style=&quot;margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; background-color: transparent; white-space: inherit;&quot;&gt;&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-keyword); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-keyword&quot;&gt;var&lt;/span&gt; input = &lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-literal); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-built_in&quot;&gt;document&lt;/span&gt;.createElement(&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;input&quot;&lt;/span&gt;);

input.setAttribute(&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;type&quot;&lt;/span&gt;, &lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;hidden&quot;&lt;/span&gt;);

input.setAttribute(&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;name&quot;&lt;/span&gt;, &lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;name_you_want&quot;&lt;/span&gt;);

input.setAttribute(&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;value&quot;&lt;/span&gt;, &lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;value_you_want&quot;&lt;/span&gt;);

&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-comment); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-comment&quot;&gt;//append to form element that you want .&lt;/span&gt;
&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-literal); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-built_in&quot;&gt;document&lt;/span&gt;.getElementById(&lt;span style=&quot;border:0px; box-sizing:inherit; color:var(--highlight-variable); font-family:inherit; font-stretch:inherit; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; margin:0px; padding:0px; vertical-align:baseline&quot; class=&quot;hljs-string&quot;&gt;&quot;chells&quot;&lt;/span&gt;).appendChild(input);&lt;/code&gt;&lt;/pre&gt;</description>
<category>Javascript</category>
<guid isPermaLink="true">http://phponlinesupport.com/359/dynamically-add-textbox-input-in-html-form-using-javascript?show=363#a363</guid>
<pubDate>Wed, 02 Jun 2021 08:48:53 +0000</pubDate>
</item>
<item>
<title>Answered: How to add auto numbering column to a Jquery datatable?</title>
<link>http://phponlinesupport.com/317/how-to-add-auto-numbering-column-to-a-jquery-datatable?show=318#a318</link>
<description>


&lt;div class=&quot;container&quot;&gt;

&lt;div class=&quot;line number1 index0 alt2&quot;&gt;&lt;code class=&quot;js plain&quot;&gt;$(document).ready(&lt;/code&gt;&lt;code class=&quot;js keyword&quot;&gt;function&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;() {&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number2 index1 alt1&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js keyword&quot;&gt;var&lt;/code&gt; &lt;code class=&quot;js plain&quot;&gt;t = $(&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;'#example'&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;).DataTable( {&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number3 index2 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;&quot;columnDefs&quot;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;: [ {&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number4 index3 alt1&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;&quot;searchable&quot;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;: &lt;/code&gt;&lt;code class=&quot;js keyword&quot;&gt;false&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;,&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number5 index4 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;&quot;orderable&quot;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;: &lt;/code&gt;&lt;code class=&quot;js keyword&quot;&gt;false&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;,&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number6 index5 alt1&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;&quot;targets&quot;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;: 0&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number7 index6 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;} ],&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number8 index7 alt1&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;&quot;order&quot;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;: [[ 1, &lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;'asc'&lt;/code&gt; &lt;code class=&quot;js plain&quot;&gt;]]&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number9 index8 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;} );&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number10 index9 alt1&quot;&gt;&amp;nbsp;&lt;/div&gt;

&lt;div class=&quot;line number11 index10 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;t.on( &lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;'order.dt search.dt'&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;, &lt;/code&gt;&lt;code class=&quot;js keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;js plain&quot;&gt;() {&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number12 index11 alt1&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;t.column(0, {search:&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;'applied'&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;, order:&lt;/code&gt;&lt;code class=&quot;js string&quot;&gt;'applied'&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;}).nodes().each( &lt;/code&gt;&lt;code class=&quot;js keyword&quot;&gt;function&lt;/code&gt; &lt;code class=&quot;js plain&quot;&gt;(cell, i) {&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number13 index12 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;cell.innerHTML = i+1;&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number14 index13 alt1&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;} );&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number15 index14 alt2&quot;&gt;&lt;code class=&quot;js spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;js plain&quot;&gt;} ).draw();&lt;/code&gt;&lt;/div&gt;

&lt;div class=&quot;line number16 index15 alt1&quot;&gt;&lt;code class=&quot;js plain&quot;&gt;} );&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;
</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/317/how-to-add-auto-numbering-column-to-a-jquery-datatable?show=318#a318</guid>
<pubDate>Wed, 05 Dec 2018 05:57:07 +0000</pubDate>
</item>
<item>
<title>Answered: Strip the HTML from a string (extract only text content) in Javascript</title>
<link>http://phponlinesupport.com/297/strip-html-from-string-extract-only-text-content-javascript?show=298#a298</link>
<description>If thats a &amp;lt;div&amp;gt; element. Please do the below.&lt;br /&gt;
&lt;br /&gt;
alert($(this).find('div').html().replace(/&amp;lt;[^&amp;gt;]+&amp;gt;/g,''));</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/297/strip-html-from-string-extract-only-text-content-javascript?show=298#a298</guid>
<pubDate>Wed, 25 Jul 2018 22:43:35 +0000</pubDate>
</item>
<item>
<title>Answered: Find all parent elements with Jquery</title>
<link>http://phponlinesupport.com/295/find-all-parent-elements-with-jquery?show=296#a296</link>
<description>Supply $(this) to the code below and you are good to go. Change the css code to your requirements as well.&lt;br /&gt;
&lt;br /&gt;
$(this).parents('li').add(this).each(function()&lt;br /&gt;
{&lt;br /&gt;
$(this).css({&amp;quot;color&amp;quot;: &amp;quot;red&amp;quot;, &amp;quot;border&amp;quot;: &amp;quot;2px solid red&amp;quot;});&lt;br /&gt;
});</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/295/find-all-parent-elements-with-jquery?show=296#a296</guid>
<pubDate>Wed, 25 Jul 2018 21:49:40 +0000</pubDate>
</item>
<item>
<title>Answered: Find all active links on a page with JS (not hashed '#')</title>
<link>http://phponlinesupport.com/293/find-all-active-links-on-a-page-with-js-not-hashed?show=294#a294</link>
<description>$('a').each(function()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (this.href[this.href.length -1] != '#')&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;alert(this.href.toLowerCase());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/293/find-all-active-links-on-a-page-with-js-not-hashed?show=294#a294</guid>
<pubDate>Wed, 25 Jul 2018 21:17:48 +0000</pubDate>
</item>
<item>
<title>Answered: How to cancel/abort an Ajax request already happened, but that I have not yet received the response from?</title>
<link>http://phponlinesupport.com/250/cancel-abort-request-already-happened-received-response-from?show=251#a251</link>
<description>


&lt;pre&gt;jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort()

$(document).ready(
    var xhr;

    var fn = function(){
        if(xhr &amp;amp;&amp;amp; xhr.readyState != 4){
            xhr.abort();
        }
        xhr = $.ajax({
            url: 'ajax/progress.ftl',
            success: function(data) {
                //do something
            }
        });
    };

    var interval = setInterval(fn, 500);
);&lt;/pre&gt;
</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/250/cancel-abort-request-already-happened-received-response-from?show=251#a251</guid>
<pubDate>Fri, 28 Jul 2017 10:54:13 +0000</pubDate>
</item>
<item>
<title>Answered: jquery verify json string</title>
<link>http://phponlinesupport.com/235/jquery-verify-json-string?show=236#a236</link>
<description>


&lt;pre&gt;Us this to verify.

function isJSON(str) 
{
    if( typeof( str ) !== 'string' ) { 
        return false;
    }
    try {
        JSON.parse(str);
        return true;
    } catch (e) {
        return false;
    }
}&lt;/pre&gt;
</description>
<category>Jquery</category>
<guid isPermaLink="true">http://phponlinesupport.com/235/jquery-verify-json-string?show=236#a236</guid>
<pubDate>Thu, 11 May 2017 06:21:22 +0000</pubDate>
</item>
</channel>
</rss>