{"id":3290,"date":"2014-03-21T20:22:56","date_gmt":"2014-03-21T20:22:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/javascriptdust-jsrelated-issues-collection-of-common-programming-errors\/"},"modified":"2014-03-21T20:22:56","modified_gmt":"2014-03-21T20:22:56","slug":"javascriptdust-jsrelated-issues-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/javascriptdust-jsrelated-issues-collection-of-common-programming-errors\/","title":{"rendered":"javascript,dust.jsRelated issues-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8ebdb3bbc86e18bde864a9536509e132?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nVzlotea<br \/>\njavascript jquery joomla mootools<br \/>\nPlease help me with a form I&#8217;m trying to do.I have a dropdown select, all the options in the &lt; select &gt; have ID&#8217;s, for example: one option has id=&#8221;hide_me&#8221;, other option has id=&#8221;hide_none&#8221;.Here is the JS that I have for the form:&lt;?php $script = &#8220;window.addEvent(&#8216;domready&#8217;, function() { $(&#8216;recipe&#8217;).addEvent(&#8216;change&#8217;, function(event) {if ( $(&#8216;recipe&#8217;)document.getElementById(&#8216;hide_it&#8217;).selected === true ) {$(&#8216;hide_me1&#8217;).setStyle(&#8216;opacity&#8217;, &#8216;1&#8217;);$(&#8216;hide_me2&#8217;).setStyle(&#8216;opacity&#8217;, &#8216;1&#8217;);} }); $(&#8216;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/58d6a9c86173bd29c9379e4ce204a8e0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\navetisk<br \/>\njavascript string truncate<br \/>\nHow do I truncate a string after or before a pattern? Say if I have a string &#8220;abcdef&#8221; I need to truncate everything after &#8220;abc&#8221; so the output will be: defand if i say truncate before &#8220;def&#8221; the output should be:abcBelow is the code that I triedvar str1 = &#8220;abcdefgh&#8221;; var str2 = str1.substr(str1.indexOf(&#8220;abc&#8221;), str1.length); console.log(str2);I didn&#8217;t get the output.I&#8217;m stuck here any help will be much appreciated.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6ceddbb4ff45fc30179db47f0336e551?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nCanna<br \/>\njavascript jquery ruby-on-rails ajax<br \/>\nTrying the basic stuff,request with data and response with data and print it with jQuery and RailsThis is the front code.$(&#8220;#internal_btn&#8221;).click(function() {\/\/window.alert(&#8220;clicked internal btn!&#8221;);$.ajax({type: &#8220;POST&#8221;,contentType: &#8220;application\/json; charset=utf-8&#8221;,url: &#8220;\/room\/test&#8221;,\/\/data: &#8220;{&#8216;data1&#8217;:'&#8221; + value1+ &#8220;&#8216;, &#8216;data2&#8217;:'&#8221; + value2+ &#8220;&#8216;, &#8216;data3&#8217;:'&#8221; + value3+ &#8220;&#8216;}&#8221;,data: {name:&#8221;ravi&#8221;,age:&#8221;31&#8243;},dataType: &#8220;json&#8221;,success: function (result) {\/\/do somthing herewindow.alert(&#8220;success!!&#8221;);},error: fun<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2807e279ada3bb19bad41a54af66114d?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNick<br \/>\njavascript arrays<br \/>\nvar fruit = [&#8220;apple&#8221;,&#8221;pear&#8221;,&#8221;pear&#8221;,&#8221;pear&#8221;,&#8221;banana&#8221;];How do I remove all &#8220;pear&#8221; fruit from this array? I tried the following, but still one pear remains:for(var f in fruit) {if ( fruit[f] == &#8220;pear&#8221; ) {fruit.splice(f, 1);} }for(var f in fruit) {document.write(fruit[f]+&#8221;&lt;br&gt;&#8221;); }Outputs:apple pear banana?What am I doing wrong? Live demo: http:\/\/jsfiddle.net\/SbxHc\/<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bc673ce429f0eb6ae81d75691522c217?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nOhgodwhy<br \/>\njavascript<br \/>\nThe function only work in the first time and not working after refreshed the page. The error message from website console is:Uncaught ReferenceError: submit_photo is not defined AddDeletePhoto.php?exhibit_id=2:1onclickUncaught SyntaxError: Unexpected token ILLEGALthis is the onlick html:&lt;a data-role=&#8221;button&#8221; data-theme=&#8221;b&#8221; href=javascript:void(0)&#8221; onclick=&#8221;submit_photo(); return false;&#8221;&gt;Upload&lt;\/a&gt;this is the JS:&lt;script type=&#8221;text\/javascript&#8221;&gt;function submit_photo() {alert(&#8220;test<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fa966a5a7e088bc99718d472489d9083?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMWA<br \/>\njavascript jquery html5 canvas<br \/>\nI have a very nice pie\/donut chart drawn with chartjs.org. Works great. Easy to implement. Animates nicely. I also have a label that needs to update when the user hovers over the chart. Mousemove fires and returns the rgba coordinately as expected in FF and IE10\/9. But not Webkit. It seems to get all mixed up&#8230; Unexpected behavior coming from Chrome\/Safari. Any idea how to fix this?This is the where the problem exist:var canvasOffset = $(this).offset(); var canvasX = Math.floor(e.pageX &#8211; canvas<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2f90e858672c079741471f72cba5480c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBen<br \/>\njavascript json node.js object asynchronous<br \/>\nI am new to Node and struggling to access a simple JSON object. My request.body will have JSON content similar to the following:{&#8220;store_config&#8221;: [{&#8220;name&#8221;: &#8220;hello&#8221;,&#8221;name2&#8243;: &#8220;world&#8221;}] }The &#8220;store_config&#8221; value will always be present, however the keys and values within could be anything.How can I iterate through the keys and values to access each? I would also like to process each in an asynchronous manner.Appreciate any thoughts or direction.UPDATEconsole.log(typeof(request.body));Returns: Objectp<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/90da7e57b59e7f9a345cbd7ecd2d7491?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAndrei Suceava<br \/>\njavascript jquery<br \/>\nI&#8217;ve been struggling with this issue for a while now. Maybe you can help.I have a table with a checkbox at the beginning of each row. I defined a function which reloads the table at regular intervals. It uses jQuery&#8217;s load() function on a JSP which generates the new table.The problem is that I need to preserve the checkbox values until the user makes up his mind on which items to select. Currently, their values are lost between updates.The current code I use that tries to fix it is:refreshId = s<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e1ac4523231d2f61e24813a574a2f08f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nZeynel<br \/>\njavascript scope google-chrome-extension<br \/>\nThis question is about a similar javascript scope problem that I asked yesterday. I hope you can help me resolve this issue.I am working with a Chrome extension. options.html saves to localStorage a new user email as &#8220;user&#8221; and calls refreshUser() function in background.html:\/\/save entered gmail address document.getElementById(&#8220;save&#8221;).addEventListener(&#8220;click&#8221;, function (){var user = document.getElementById(&#8220;getEmail&#8221;).value;localStorage.setItem(&#8220;user&#8221;, user);chrome.extension.getBackgroundPage().<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5b759d810e5691383ca0b4723a0ba595?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDavid Faux<br \/>\njavascript google-visualization<br \/>\nI am trying to program a bar chart using Google Visualizations.https:\/\/developers.google.com\/chart\/interactive\/docs\/gallery\/barchartThe bar chart is dynamically generated and changed several times.Google Visualizations seems to have trouble detecting the dimensions of a div element that I dynamically appended via jQuery. Hence, I would like to hard code the dimensions of the bar chart into the options that I feed into Google Visualizations. How do I do that?I have tried these options.var options<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a1836a522950d64cd335f509865548a0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAVP<br \/>\nhtml web jade dust.js<br \/>\nI&#8217;ve been looking all over for something that will let me precompile static websites using Grunt. It needs to have partials, so I can include things like a common header\/footer across the pages.So far, I&#8217;ve only really found Jade, which has a grunt plugin, and this plugin for Grunt that compiles Dust.js templates to static HTML. I don&#8217;t really like Jade&#8217;s syntax, and the Dust plugin for Grunt is less than ideal. Any suggestions for a good static HTML templating language with Grunt support?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/6bHP9.png?s=32&amp;g=1\" \/><br \/>\nergoon<br \/>\njavascript node.js mongodb mongoose dust.js<br \/>\nI have a dust.js template that should render a JSON object coming from a mongodb collection.{&#8220;author&#8221;: &#8220;Leslie Horn&#8221;,&#8221;title&#8221;: &#8220;An Awesome 132-Cube Ice Tray Exists Because People Are Assholes&#8221;,&#8221;published&#8221;: &#8220;2013-06-13T21:00:00.000Z&#8221;,&#8221;link&#8221;: &#8220;http:\/\/gizmodo.com\/an-awesome-132-cube-ice-tray-exists-because-people-are-513229668&#8243;,&#8221;feed&#8221;: {&#8220;link&#8221;: {&#8220;xml&#8221;: &#8220;feed\/http:\/\/feeds.gawker.com\/gizmodo\/excerpts.xml&#8221;,&#8221;html&#8221;: &#8220;http:\/\/gizmodo.com&#8221;},&#8221;title&#8221;: &#8220;Gizmodo&#8221;},&#8221;summary&#8221;: &#8220;&lt;p&gt;&lt;img alt=\\&#8221;An Awesome 1<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/45dae809c665a65f8561fccf6ad42898?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nElankeeran<br \/>\nnode.js express dust.js<br \/>\nIn expressjs, Dustjs Multiple templates not working getting 500 Error: Template Not Found: templatemy base dust template as below (template.dust)&lt;div class=&#8221;page&#8221;&gt;{+pageHeader}Hello World!{\/pageHeader}&lt;div class=&#8221;bodyContent&#8221;&gt;{+bodyContent\/}&lt;\/div&gt;&lt;div class=&#8221;footer&#8221;&gt;{+pageFooter}&lt;hr&gt;&lt;a href=&#8221;\/contactUs&#8221;&gt;Contact Us&lt;\/a&gt;{\/pageFooter}&lt;\/div&gt; &lt;\/div&gt;And I am trying to call this base template inside my home.dust I am getting error as belowExpress 500<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/nZEUQ.png?s=32&amp;g=1\" \/><br \/>\nPeeHaa<br \/>\nphp jquery dust.js<br \/>\nCurrent I did the dustjs in client javascript as below&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;script src=&#8221;lib\/dust-full-0.3.0.min.js&#8221; type=&#8221;text\/javascript&#8221;&gt;&lt;\/script&gt;&lt;script src=&#8221;vendor\/jquery-1.7.1.min.js&#8221; type=&#8221;text\/javascript&#8221;&gt;&lt;\/script&gt;&lt;script type=&#8221;text\/javascript&#8221;&gt;$(document).ready(function(){\/\/ JSON response from server var json_object = { &#8220;profile_skill&#8221;: &#8220;Profile Skill&#8221;,&#8221;skills&#8221;: [{ &#8220;name&#8221;: &#8220;JavaScript&#8221; },{ &#8220;name&#8221;: &#8220;Ruby&#8221; },{ &#8220;name&#8221;: &#8220;Java&#8221; }]}\/\/ re<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/56533d50fdfceb887852bf50be54678b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nnalply<br \/>\nhtml dust.js<br \/>\nThe partials were used in the this way but I was getting output as undefined. Created two template files parent and child that inherits from parent.parent.tl:&lt;div&gt;&lt;span&gt;&lt;label&gt;{+title}New{\/title}&lt;\/label&gt;&lt;\/div&gt;child.tl:{&gt;&#8221;parent&#8221;\/}{&lt;title}{#t}&lt;p&gt;NEW {title1} For the Child&lt;\/p&gt;{\/t} {\/title}I compiled those templates using dustr and included as .js in my HTML.&lt;script src=&#8221;https:\/\/raw.github.com\/akdubya\/dustjs\/master\/dist\/dust-full-0.3.0.min.js&#8221;&amp;g<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bfad81ce3faaa9c12b5cd04eba23cca5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ngodspeed<br \/>\ndust.js<br \/>\nI&#8217;ve just started using dust.js. And I&#8217;ve come across a problem. I need to specify a condition (json parameters existence) in template. Depending on it some inner html should be rendered or not. So according to the description I should use smth like this:{?param_name} &#8230; {:else} {\/param_name}But I need to check a complex condition, so I go for logic helper &#8211; {@if..}. And it turns out that I&#8217;d like to use path in condition. So.. The result looks:{@if cond=&#8221;{myObject.property1} || {myObject.prope<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0a9380f35d52fd24ae753a1186878b55?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKevin Leary Boston WordPress<br \/>\njavascript jquery asp.net-mvc json dust.js<br \/>\nI&#8217;m working with jQuery 1.8.2 &amp; Dust.js v1.1.1 for MVC-style templating within a JavaScript app. When I use the {@gt} logic helper I receive the following console error:Uncaught TypeError: Cannot read property &#8216;gt&#8217; of undefinedI believe the proper syntax is used in my template:&lt;ul class=&#8221;listview&#8221;&gt; {#seasons}&lt;li&gt;&lt;h3&gt;{name}&lt;\/h3&gt;&lt;p class=&#8221;desc&#8221;&gt;{id}&lt;\/p&gt;{@gt key=&#8221;months&#8221; value=&#8221;0&#8243;}&lt;span class=&#8221;count&#8221;&gt;{months}&lt;\/span&gt;{\/gt}&lt;\/li&gt; {\/seasons} &lt;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/639ced0d6d8b40ff2472650a8e349145?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJim<br \/>\njavascript dust.js<br \/>\nI&#8217;m using the full, Linked In version 1.2.0 of dust.js and am trying to define a filter for use when rendering a JSON view with a dust template. When I include this line in the page script:_.extend(dust.filters, {foo: function(value){ return &#8216;foo&#8217;; }});it results in this error in Chrome&#8217;s debugger:Uncaught ReferenceError: _ is not defined If I add the filter definition to where the other filters are in the dust .js file, it works. What am I doing wrong?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/639ced0d6d8b40ff2472650a8e349145?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJim<br \/>\njavascript dust.js<br \/>\nI&#8217;m trying to render HTML using compiled templates with dust.js in a browser (not server-side with node.js). If I compile the template in the client-side javascript, it works fine. If I pre-compile the template and include it as a script tag as recommended, the dust.loadSource statement results in the Chrome debugger saying: &#8220;Uncaught ReferenceError: nowork is not defined&#8221;, where &#8220;nowork&#8221; is the template name. So&#8230;This HTML and script works:&lt;!DOCTYPE html&gt; &lt;html lang=&#8221;en&#8221;&gt; &lt;head&amp;<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vzlotea javascript jquery joomla mootools Please help me with a form I&#8217;m trying to do.I have a dropdown select, all the options in the &lt; select &gt; have ID&#8217;s, for example: one option has id=&#8221;hide_me&#8221;, other option has id=&#8221;hide_none&#8221;.Here is the JS that I have for the form:&lt;?php $script = &#8220;window.addEvent(&#8216;domready&#8217;, function() { $(&#8216;recipe&#8217;).addEvent(&#8216;change&#8217;, function(event) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3290","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3290"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3290\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}