UNPKG

elasticlunr

Version:

Lightweight full-text search engine in Javascript for browser search and offline search.

1 lines 842 kB
{"version":"0.9.5","fields":["title","tags","body"],"ref":"id","documentStore":{"docs":{"78932":{"id":78932,"title":"How do I programatically set the value of a select box element using javascript?","body":"<p>I have the following HTML select element:</p>\n\n<pre><code>&lt;select id=\"leaveCode\" name=\"leaveCode\"&gt;\n &lt;option value=\"10\"&gt;Annual Leave&lt;/option&gt;\n &lt;option value=\"11\"&gt;Medical Leave&lt;/option&gt;\n &lt;option value=\"14\"&gt;Long Service&lt;/option&gt;\n &lt;option value=\"17\"&gt;Leave Without Pay&lt;/option&gt;\n&lt;/select&gt;\n</code></pre>\n\n<p>Using a javascript function with the leave code number as a parameter, how do I select the appropriate option in the list?</p>\n","tags":"javascript html dom"},"318630":{"id":318630,"title":"Get real image width and height with Javascript in Safari/Chrome?","body":"<p>I am creating a jQuery plugin.</p>\n\n<p>How do I get real image width and height with Javascript in Safari?</p>\n\n<p>Following works with Firefox 3, IE7 and Opera 9:</p>\n\n<pre><code>var pic = $(\"img\")\n\n// need to remove these in of case img-element has set width and height\npic.removeAttr(\"width\"); \npic.removeAttr(\"height\");\n\nvar pic_real_width = pic.width();\nvar pic_real_height = pic.height();\n</code></pre>\n\n<p>But in Webkit browsers like Safari and Google Chrome values are 0...</p>\n\n<p>Doing this on server side is not an option.</p>\n","tags":"javascript jquery safari google-chrome webkit"},"814910":{"id":814910,"title":"Animating Background Image","body":"<p>I Like using Jquery and its companion Jquery Ui but can not find a way to animate background image over a certain period of time like 5 seconds.\nI can not do something like:</p>\n\n<pre><code>$('sampleelement').animate({'background-image':'url(hello.jpg)'},5000);\n</code></pre>\n\n<p>Any ideas??</p>\n","tags":"javascript jquery jquery-ui animation jquery-animation"},"3047391":{"id":3047391,"title":"Parsing complex string using regex","body":"<p>My regex skills are not very good and recently a new data element has thrown my parser into a loop</p>\n\n<p>Take the following string</p>\n\n<p>\"+USER=Bob Smith-GROUP=Admin+FUNCTION=Read/FUNCTION=Write\"</p>\n\n<p>Previously I had the following for my regex : [+\\\\-/]</p>\n\n<p>Which would turn the result into </p>\n\n<p>USER=Bob Smith<br>\nGROUP=Admin<br>\nFUNCTION=Read<br>\nFUNCTION=Write<br>\nFUNCTION=Read </p>\n\n<p>But now I have values with dashes in them which is causing bad output</p>\n\n<p>New string looks like \"+USER=Bob Smith-GROUP=Admin+FUNCTION=Read/FUNCTION=Write/FUNCTION=Read-Write\"</p>\n\n<p>Which gives me the following result , and breaks the key = value structure.</p>\n\n<p>USER=Bob Smith<br>\nGROUP=Admin<br>\nFUNCTION=Read<br>\nFUNCTION=Write<br>\nFUNCTION=Read<br>\nWrite </p>\n\n<p>Can someone help me formulate a valid regex for handling this or point me to some key / value examples. Basically I need to be able to handle + - / signs in order to get combinations.</p>\n","tags":"java javascript xml regex parsing"},"3802824":{"id":3802824,"title":"Problem opening page with javascript pop ups in android webview","body":"<p>I am very new to both Android WebKit and JavaScript. I have a web page with 3 links (say A,B,C). When I open that page on my PC browser(Chrome) and click on the links, A opens in the same browser window, whereas B and C pops up a new window. In my android application I am \nloading the original URL in a WebView. I have implemented my WebViewClient and overridden the <code>shouldOverrideUrlLoading</code>. I am getting the call to <code>shouldOverrideUrlLoading</code> whenever I click on A, but not getting it when I click on B or C? </p>\n\n<p>I went through the page source and it looks like the 2 links that are \nnot supported are opened as IFRAMEs. are IFRAMEs supported by WebView? </p>\n\n<p>Thanks </p>\n\n<p>KK</p>\n","tags":"javascript android"},"3827055":{"id":3827055,"title":"Run JavaScript unit tests inside of Visual Studio 2010","body":"<p>I have been searching for a good way to run JavaScript unit tests inside of the Visual Studio 2010 IDE. I currently use <a href=\"http://www.testdriven.net/\" rel=\"nofollow\">TestDriven.net</a> to run my C# units tests and it is very convenient to be able to quickly get the result of my tests in the output pane. I would love to find a similar experience for JavaScript (ideally working with TestDriven.net).</p>\n\n<p>I have read about different solutions that let you execute JavaScrpt unit tests. Some have their own JS engine while others like <a href=\"http://code.google.com/p/js-test-driver/\" rel=\"nofollow\">JS-Test-Driver</a> are able to send the code to the browsers and fetch the results. But I have yet to see something that is integrated into VS 2010.</p>\n\n<p>Does anyone know of an extension that might do this?</p>\n","tags":"javascript unit-testing visual-studio-2010"},"4047072":{"id":4047072,"title":"JS: setInterval and blur.","body":"<p>I have this:</p>\n\n<pre><code>$(window).blur(function() {\n setInterval(function() {\n $.ajax({\n type: \"POST\",\n url: \"imback.php\",\n data: {\n mode: 'ajax',\n getUpdates: 'auto',\n },\n success: function(msg){\n document.title = msg + titleOrig;\n }\n });\n }, 35000);\n</code></pre>\n\n<p>Works fine.</p>\n\n<p>Although, if you have been blur, and then when you focus back, it will keep making the ajax call, it doesnt stop sending ajax call after interval 35 seconds. </p>\n\n<p>How can i fix this?\n })</p>\n","tags":"javascript"},"4185821":{"id":4185821,"title":"Is it possible to programmatically detect the caret position within a <input type=text> element?","body":"<p>Assuming a regular <code>&lt;input type=text&gt;</code> text-box with data in it. </p>\n\n<p>Is it possible to detect (via JavaScript) the position of the text-coursor inside that text-box? </p>\n\n<p>I am able to detect an ARROW LEFT or ARROW RIGHT keydown event - but how to detect the cursor location? </p>\n\n<p><em><strong>Why I need this:</em></strong> </p>\n\n<p>I have a dynamic text-box here: <a href=\"http://vidasp.net/tinydemos/dynamic-textbox.html\" rel=\"nofollow\">http://vidasp.net/tinydemos/dynamic-textbox.html</a><br>\nIt works great, however there are two scenarios that I would like to fix: </p>\n\n<ol>\n<li>when the cursor is at the beginning of the text-box and the user presses BACKSPACE </li>\n<li>when the cursor is at the end of the text-box and the user presses DELETE </li>\n</ol>\n\n<p>(In both cases, the text-box must contain data for the effect to be observable.)</p>\n","tags":"javascript"},"4272538":{"id":4272538,"title":"How can I parse XML in javascript in both IE and firefox?","body":"<p>I'm trying to write a single piece of code to parse javascript in both IE and firefox.</p>\n\n<p>The following works in IE, and functions without complaining in firefox</p>\n\n<pre><code>function XmlDom(sXml){\n var oXml;\n if (window.ActiveXObject) {\n // ie\n oXml = new ActiveXObject(\"Microsoft.XMLDOM\");\n oXml.resolveExternals = false;\n oXml.async = false;\n oXml.loadXML(sXml);\n }\n else if (window.DOMParser){\n\n var parser = new DOMParser(); \n oXml = parser.parseFromString(sXml, \"text/xml\");\n\n }\nreturn oXml\n}\n</code></pre>\n\n<p>The following works in IE, but gives errors (because childNodes doesn't exist) under Firefox</p>\n\n<pre><code>var oXml = XmlDom(sourceXML);\nvar listHtml = \"\";\nif (oXml.firstChild != null) {\n var childNodes = null;\n try {\n childNodes = oXml.lastChild.lastChild.firstChild.childNodes;\n }\n if (childNodes != null &amp;&amp; childNodes.length &gt; 0) {\n\n for (var i = 0; i &lt; childNodes.length; i++) {\n\n var vehicleName = NodeText(SelectSingleNode(childNodes[i], 'VehicleName', 'VehicleName'));\n var vehicleId = NodeText(SelectSingleNode(childNodes[i], 'VehicleId', 'VehicleId'));\n\n }\n }\n}\n</code></pre>\n\n<p>Using jquery gives me correct behavior under firefox, but doesn't quite work in IE (it finds the correct number of vehicles, but each one has a null id and name)</p>\n\n<pre><code> $(sourceXml).find(\"Table1\").each(function() {\n var vehicleId = $(this).find(\"VehicleId\").text();\n var vehicleName = $(this).find(\"VehicleName\").text();\n });\n</code></pre>\n\n<p>I firmly believe that both these approaches <em>should</em> work. But something is going wrong. I'd love a hand.</p>\n\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"utf-16\"?&gt;\n&lt;DataSet&gt;\n &lt;xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" xmlns:msprop=\"urn:schemas-microsoft-com:xml-msprop\"&gt;\n &lt;xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\"&gt;\n &lt;xs:complexType&gt;\n &lt;xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"&gt;\n &lt;xs:element name=\"Table1\"&gt;\n &lt;xs:complexType&gt;\n &lt;xs:sequence&gt;\n &lt;xs:element name=\"VehicleId\" msprop:metadatacolumnname=\"VehicleId\" msprop:caption=\"VehicleId\" type=\"xs:string\" minOccurs=\"0\" /&gt;\n &lt;xs:element name=\"VehicleName\" msprop:metadatacolumnname=\"VehicleName\" msprop:caption=\"VehicleName\" type=\"xs:string\" minOccurs=\"0\" /&gt;\n &lt;xs:element name=\"SendAlarms\" msprop:metadatacolumnname=\"SendAlarms\" msprop:caption=\"SendAlarms\" type=\"xs:string\" minOccurs=\"0\" /&gt;\n &lt;/xs:sequence&gt;\n &lt;/xs:complexType&gt;\n &lt;/xs:element&gt;\n &lt;/xs:choice&gt;\n &lt;/xs:complexType&gt;\n &lt;/xs:element&gt;\n &lt;/xs:schema&gt;\n &lt;diffgr:diffgram xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" xmlns:diffgr=\"urn:schemas-microsoft-com:xml-diffgram-v1\"&gt;\n&lt;NewDataSet&gt;\n &lt;Table1 diffgr:id=\"Table11\" msdata:rowOrder=\"0\" diffgr:hasChanges=\"inserted\"&gt;\n &lt;VehicleId&gt;8&lt;/VehicleId&gt;\n &lt;VehicleName&gt;AIS Gate&lt;/VehicleName&gt;\n &lt;SendAlarms&gt;False&lt;/SendAlarms&gt;\n &lt;/Table1&gt;\n &lt;Table1 diffgr:id=\"Table12\" msdata:rowOrder=\"1\" diffgr:hasChanges=\"inserted\"&gt;\n &lt;VehicleId&gt;82&lt;/VehicleId&gt;\n &lt;VehicleName&gt;Amigos&lt;/VehicleName&gt;\n &lt;SendAlarms&gt;False&lt;/SendAlarms&gt;\n &lt;/Table1&gt; \n&lt;/NewDataSet&gt;\n&lt;/diffgr:diffgram&gt;\n&lt;/DataSet&gt;\n</code></pre>\n","tags":"javascript xml"},"4460205":{"id":4460205,"title":"detect ipad/iphone webview via javascript","body":"<p>Is there a way to differ via javascript if the website runs inside the ipad safari or inside an application WebView?</p>\n","tags":"javascript ipad ios webview"},"4508230":{"id":4508230,"title":"php/ajax user actions undo manager","body":"<p>does exist a library that gives you undo/redo capability with history for a web app? An idea would be a php/javascript/ajax system in which you can register for every user action an opposite action and the variable state (like a normal undo manager!). and it should work both at client level and server level.</p>\n\n<p>Did i ask too much?</p>\n","tags":"php javascript ajax undo-redo"},"4529460":{"id":4529460,"title":"How to fix the width and height of jquery lightbox?","body":"<p>I have aplied jquery lighbox on my image gallery, but due to the variable size of images, the lightbox size is not fixed hence opens up with image's original size, this in turn causes the biga images to go out of screen and display horizontal scroll bar in browser.</p>\n\n<p>Hence I am looking for the way to apply the fix width and height to lightbox so that every image must be displayed with this size in lightbox.</p>\n\n<p>Please help..</p>\n\n<blockquote>\n <p><strong>Update</strong></p>\n</blockquote>\n\n<p>i Just tried with the solution Scott (<a href=\"http://geekswithblogs.net/wojan/archive/2009/06/17/jquerylightbox.aspx\" rel=\"nofollow\">http://geekswithblogs.net/wojan/archive/2009/06/17/jquerylightbox.aspx</a>) has given to me, I did this,</p>\n\n<pre><code>function _resize_container_image_box(intImageWidth,intImageHeight) {\n// Get current width and height\n//rescale if necessary\nif((settings.maxWidth != null &amp;&amp; settings.maxHeight != null) &amp;&amp; (intImageWidth &gt; settings.maxWidth || intImageHeight &gt; settings.maxHeight)){\nvar isWider = intImageWidth &gt; intImageHeight;//is the image wide or tall?\nvar scale = isWider ? settings.maxWidth/intImageWidth : settings.maxHeight/intImageHeight;\nintImageWidth = intImageWidth * scale;\nintImageHeight = intImageHeight * scale;\n}\n\n$('#lightbox-image').height(intImageHeight); \n$('#lightbox-image').width(intImageWidth); \nvar intCurrentWidth = $('#lightbox-container-image-box').width();\nvar intCurrentHeight = $('#lightbox-container-image-box').height();\n// Get the width and height of the selected image plus the padding\nvar intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image´s width and the left and right padding value\nvar intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image´s height and the left and right padding value\n// Diferences\nvar intDiffW = intCurrentWidth - intWidth;\nvar intDiffH = intCurrentHeight - intHeight;\n// Perfomance the effect\n$('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });\nif ( ( intDiffW == 0 ) &amp;&amp; ( intDiffH == 0 ) ) {\nif ( $.browser.msie ) {\n___pause(250);\n} else {\n___pause(100); \n}\n} \n$('#lightbox-container-image-data-box').css({ width: intImageWidth });\n$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });\n};\n</code></pre>\n\n<p>AND</p>\n\n<pre><code>$('#gallery a').lightBox( maxHeight: null,\nmaxWidth: null);\n});\n</code></pre>\n\n<p>But whenever I do this and click on the image just gets open in browsers annother tab, all the lightbox functinalty fails</p>\n\n<p>Please help me to correct it</p>\n\n<p>Thanks</p>\n","tags":"javascript jquery css lightbox"},"5306132":{"id":5306132,"title":"Translate Javascript keyCode into charCode for non-U.S. keyboard layout (i.e. azerty)","body":"<p>Quick background:</p>\n\n<ul>\n<li>when a key is pressed in a browser, three events are generated: <strong>keyDown</strong>, <strong>keyPress</strong> and <strong>keyUp</strong>.</li>\n<li><strong>keyDown</strong> and <strong>keyUp</strong> have a <strong>keyCode</strong> property which is approximately the physical key pressed.</li>\n<li><strong>keyPress</strong> also has <strong>charCode</strong> property set which takes into account modifier keys and keyboard layout (A and a have same keyCode but a different charCode).</li>\n<li>all three events have properties that indicate which modifier keys were pressed during those events.</li>\n</ul>\n\n<p>I'm the main <a href=\"https://github.com/kanaka/noVNC\" rel=\"nofollow\">noVNC</a> developer and I have a tough problem: noVNC needs the translated <strong>charCode</strong> value without using the <strong>keyPress</strong> event for the following reasons:</p>\n\n<ul>\n<li>noVNC needs to send the keyDown and keyUp events separately to the VNC server (otherwise it's not a completely functional VNC client).</li>\n<li>more importantly, noVNC needs to prevent the default keyboard actions while connected which means calling the <strong>preventDefault()</strong> method of the <strong>keyDown</strong> event. This has the side-effect of also preventing the <strong>keyPress</strong> event from firing.</li>\n</ul>\n\n<p>Due to differences in keyboard layouts (i.e. different keyCode to charCode mappings) I've determine that noVNC will need a lookup table for different keyboard layouts.</p>\n\n<p><strong>But here is the real problem:</strong> on alternate layouts, some different physical keys have the <strong>SAME</strong> keyCode. For example, with an <strong>azerty</strong> (French) keyboard layout the '-' (dash) and '_' underscore keys both generate keyCode 189. Ack!!!</p>\n\n<p>So ... how do I get proper keyCode to charCode mapping and prevent default browser actions at the same time?</p>\n\n<p>BTW, I suspect the solution to this will be applicable to other interactive web applications and HTML5 games since you often want to be able to know full information about the key pressed without triggering any additional browser response to that keypress.</p>\n\n<p>Useful links:</p>\n\n<ul>\n<li><a href=\"http://kanaka.github.com/noVNC/noVNC/tests/keyboard.html\" rel=\"nofollow\">Here</a> is an useful test page that show the three events and some other useful properties.</li>\n<li><a href=\"http://unixpapa.com/js/key.html\" rel=\"nofollow\">Summary</a> of the crazy state of key events in Javascript (thanks @Tim)</li>\n<li>Quirksmode <a href=\"http://www.quirksmode.org/js/keys.html\" rel=\"nofollow\">Detecting keystrokes</a></li>\n<li>Quirksmode <a href=\"http://www.quirksmode.org/dom/events/tests/keys.html\" rel=\"nofollow\">Events - key events</a></li>\n<li><a href=\"https://github.com/kanaka/noVNC/issues/#issue/21\" rel=\"nofollow\">noVNC issue</a> with more discussion of the problem.</li>\n</ul>\n\n<p><strong>Solution</strong>: see my post below.</p>\n","tags":"javascript html5 browser cross-browser"},"5351143":{"id":5351143,"title":"how to create autocomplete forum using html5 local storage?","body":"<p>Hi to all, I am new to programming. will you help me to write code for autocomplete text fields in a html form. I want to use local storage data.\nIf any time user will inter some data in text field, it will be stored in local storage. if next time when he enters data then, localstorage data related to that field will appear as popup(like mozila or chrome autocomplete).</p>\n\n<p>please provide me some guidelines</p>\n","tags":"javascript forms html5 autocomplete localstorage"},"5549729":{"id":5549729,"title":"JQuery Mobile Calendar ?","body":"<p>Does anyone know of any Calendar that I could use on JQuery Mobile? </p>\n\n<p>Needs to be able to save dates locally etc.</p>\n\n<p>Thanks</p>\n","tags":"javascript html5 jquery-mobile"},"6174688":{"id":6174688,"title":"jquery ajax post call issue with special chracters [solved]","body":"<p>Solution: i guess the problem was related to firefox as a browser. I solved making the ajax call pass through a php proxy..</p>\n\n<p>i have a form with two data fields (a checkbox and a textarea) sent via an ajax call. \nThe tomcat server response is an html page with some javascript code in it. I must use the POST method given the amount of data to be sent (if i could use GET i woud not have this issue!).\nThe problem arises if i send accented characters (èàòù) throught the textarea, for which i get weird question marks in place of them.\nFrom the firebug console i can see that both sent and received data are utf-8 encoded:</p>\n\n<p>SENT DATA: Content-Type application/x-www-form-urlencoded; charset=UTF-8 \nRECEIVED DATA: text/html;charset=UTF-8</p>\n\n<p>The problem does not show in chrome or IE, but only in firefox and on all browsers on mac. HAve anybody any suggestione about this?</p>\n\n<p>Thanks\nVitto</p>\n","tags":"javascript jquery ajax post"},"6294393":{"id":6294393,"title":"Navigation Menu Hover Effect only on a Particular Occasion","body":"<p>I need the exact effect of this website's navigation menu <a href=\"http://recruitmentmalta.com/ptowers/\" rel=\"nofollow\">http://recruitmentmalta.com/ptowers/</a> but in neater code. This code was generated with a tool which converts from PSD to HTML/CSS and basically created a bunch of useless code. I know how to make that menu, except for the part where the Shop Now effect should turn off only if the contact is hovered over.</p>\n\n<p>Any ideas of how I can recreate that hovering off effect when I hover over the contact button (when Shop Now gets turned off)? </p>\n\n<p>This is what I have done so far to give you an idea</p>\n\n<pre><code> &lt;ul&gt;\n &lt;li id=\"homeButton\"&gt; &lt;img src=\"images/home.png\" onmouseout=\"this.src='images/home.png'\" onmouseover=\"this.src='images/homeHover.png'\" width=\"115\" height=\"55\" alt=\"home\" /&gt;&lt;/li&gt;\n &lt;li id=\"aboutButton\"&gt; &lt;img src=\"images/about.png\" onmouseout=\"this.src='images/about.png'\" onmouseover=\"this.src='images/aboutHover.png'\" width=\"115\" height=\"55\" alt=\"about\" /&gt;&lt;/li&gt;\n &lt;li id=\"newsButton\"&gt; &lt;img src=\"images/news.png\" onmouseout=\"this.src='images/news.png'\" onmouseover=\"this.src='images/newsHover.png'\" width=\"115\" height=\"55\" alt=\"news\" /&gt;&lt;/li&gt;\n &lt;li id=\"brandsButton\"&gt; &lt;img src=\"images/brands.png\" onmouseout=\"this.src='images/brands.png'\" onmouseover=\"this.src='images/brandsHover.png'\" width=\"115\" height=\"55\" alt=\"brands\" /&gt;&lt;/li&gt;\n &lt;li id=\"storesButton\"&gt; &lt;img src=\"images/stores.png\" onmouseout=\"this.src='images/stores.png'\" onmouseover=\"this.src='images/storesHover.png'\" width=\"115\" height=\"55\" alt=\"stores\" /&gt;&lt;/li&gt;\n &lt;li id=\"careersButton\"&gt; &lt;img src=\"images/careers.png\" onmouseout=\"this.src='images/careers.png'\" onmouseover=\"this.src='images/careersHover.png'\" width=\"115\" height=\"55\" alt=\"careers\" /&gt;&lt;/li&gt;\n &lt;li id=\"contactButtonMenu\"&gt; &lt;img src=\"images/contactButton.png\" onmouseout=\"this.src='images/contactButton.png'\" onmouseover=\"this.src='images/contactButtonHover.png'\" width=\"115\" height=\"55\" alt=\"contact\" /&gt;&lt;/li&gt;\n &lt;li id=\"shopNowButton\"&gt; &lt;img src=\"images/shopNowHover.png\" width=\"114\" height=\"53\" alt=\"Shop Now\" /&gt; &lt;/li&gt;\n &lt;/ul&gt;\n</code></pre>\n\n<p>This is my JS Fiddle Link: <a href=\"http://jsfiddle.net/GHHJM/\" rel=\"nofollow\">http://jsfiddle.net/GHHJM/</a></p>\n","tags":"javascript jquery html css menu"},"6296451":{"id":6296451,"title":"problem in file upload","body":"<p>I have the following markup:</p>\n\n<pre><code> &lt;select multiple=\"multiple\" id=\"targetFilesList\" style=\"width:200px;height:110px;\"&gt;\n &lt;/select&gt;\n &lt;input type=\"button\" value=\"Get\" id=\"btnGet\" /&gt;\n</code></pre>\n\n<p>and following javascript:</p>\n\n<pre><code> $(function()\n {\n $('#btnGet').click(function()\n {\n var fileupload = $(\"&lt;input type='file' name='filetoupload' style='visibility:hidden;'/&gt;\");\n $('body').append(fileupload);\n\n fileupload[0].onchange = function()\n {\n $('#targetFilesList').append('&lt;option &gt;' + fileupload.val() + '&lt;/option&gt;');\n return false;\n }\n fileupload.click();\n });\n });\n</code></pre>\n\n<p>Scenario is that i have to upload multiple files and once user has chosen the file to be uploaded i have to show the file name to user.Then,on submitting the form i will upload all the files.For this,on clicking the get button i am adding a fileupload control dynamically\nand initialise onchange event of the fileupload control just added. The problem in chrome 12 on clicking get button fileupload control does not get opened but in firefox4 and ie8 it is working.\nAny idea why?</p>\n","tags":"javascript jquery html file-upload"},"6364675":{"id":6364675,"title":"HtmlUnit's HtmlPage.getElementById seems to reinitialize JavaScript after many calls.","body":"<p>I have a simple HTML page (ratings.html) that I'm trying to test using HtmlUnit. The action that I'm testing works when I load it up in a browser and do it by hand. However, when I try to test it with HtmlUnit, it seems like too many calls to getElementById (or getInputByName) cause the JavaScript on the page to be reinitialized.</p>\n\n<p>In the AddRating.scala test, the first two calls to page.addRating work, but the third fails because it can't find the 'rating3' element on the page. After lots of debugging, I've discovered that the <code>ratingCount</code> gets reset back to 0 for some reason.</p>\n\n<p>See my comments below (between the <code>// ******</code> sections) to see where the problem areas are.</p>\n\n<p>Has anyone else experience this behavior or have any advice on how to deal with it? Thanks!</p>\n\n<p><strong>ratings.html (HTML Page to add \"ratings\"):</strong></p>\n\n<pre><code>&lt;html&gt;\n &lt;head&gt;\n &lt;script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js\"&gt;&lt;/script&gt;\n &lt;script src=\"http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js\"&gt;&lt;/script&gt;\n &lt;/head&gt;\n &lt;body&gt;\n &lt;form name=\"new-rating\" method=\"post\" action=\"/add-rating\"&gt;\n &lt;table&gt;\n &lt;tr&gt;\n &lt;td valign=\"top\"&gt;Ratings:&lt;/td&gt;\n &lt;td&gt;\n Should be ordered from best to worst.&lt;br&gt;\n &lt;a id=\"add-rating\" href=\"#\"&gt;add rating&lt;/a&gt;&lt;/td&gt;\n &lt;/tr&gt;\n &lt;tr&gt;\n &lt;td&gt;&lt;/td&gt;\n &lt;td&gt;\n &lt;button name=\"submit-button\" type=\"submit\"&gt;Add Rating&lt;/button&gt;\n &lt;/td&gt;\n &lt;/tr&gt;\n &lt;/table&gt;\n &lt;/form&gt;\n &lt;h2&gt;All Ratings&lt;/h2&gt;\n\n &lt;ul id=\"ratings\"&gt;\n &lt;/ul&gt;\n\n &lt;script&gt;\n $(window).load(function(){ \n // display ratings\n $.getJSON(\"/ratings\", function(data)\n {\n var items = $.map(data, function(el) {\n var ratingsTable = \"\";\n if (el.ratings.length &gt; 0)\n {\n $.tmpl(\"&lt;li&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Rating&lt;/th&gt;&lt;/tr&gt;{{each ratings }}&lt;tr&gt;&lt;td&gt;${$value.label}&lt;/td&gt;&lt;/tr&gt;{{/each}}&lt;/table&gt;&lt;/li&gt;\", el).appendTo(\"#ratings\");\n }\n });\n });\n\n // add rating action\n // ***********\n var ratingCount = 0; // THIS GETS RE-INITIALIZED TO 0 AFTER TOO MANY getElementById or getElementByName calls.\n // ***********\n $('#add-rating').click(function()\n {\n ratingCount += 1;\n $('#remove-rating').show();\n $.tmpl(\"&lt;span id='rating${ratingId}'&gt;&lt;input name='rating${ratingId}'&gt;&lt;br&gt;&lt;/span&gt;\",\n {ratingId: ratingCount}).insertBefore('#add-rating');\n if(ratingCount &gt;= 5) { $('#add-rating').hide(); }\n });\n });\n &lt;/script&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p><strong>RatingsPage.scala (Scala interface to HTML page):</strong></p>\n\n<pre><code>package portal\n\nimport com.gargoylesoftware.htmlunit.WebClient\nimport com.gargoylesoftware.htmlunit.html._\n\nimport infrastructure.SuperHtmlUnitConversions._\n\nimport infrastructure.WaitFor\n\nclass RatingsPage(page: HtmlPage)\n{\n val newRatingForm: HtmlForm = page.getFormByName(\"new-rating\")\n\n var ratingCount = 0\n\n def submit(): RatingsPage =\n {\n val page = newRatingForm.getButtonByName(\"submit-button\").click[HtmlPage]()\n ratingCount = 0\n new RatingsPage(page)\n }\n\n def addRating(rating: String)\n {\n page.getElementById(\"add-rating\").click()\n ratingCount += 1\n newRatingForm.getInputByName(\"rating\" + ratingCount).asInstanceOf[HtmlInput].setValueAttribute(rating)\n }\n\n def asText(): String = page.asText\n def asXml(): String = page.asXml\n}\n</code></pre>\n\n<p><strong>AddRating.scala (Scala HtmlUnit test that fails):</strong></p>\n\n<pre><code>package portal\n\nimport java.util.Date\nimport org.scalatest.FunSuite\nimport org.scalatest.junit.JUnitRunner\nimport org.junit.runner.RunWith\nimport org.scalatest.matchers.ShouldMatchers\nimport com.gargoylesoftware.htmlunit.WebClient\nimport com.gargoylesoftware.htmlunit.html._\nimport infrastructure.WaitFor\n\n@RunWith(classOf[JUnitRunner])\nclass AddRating extends FunSuite with ShouldMatchers\n{\n test(\"add ratings\")\n {\n val client = new WebClient()\n val index = new PortalIndexPage(client)\n var page = index.goToRatingsPage()\n\n page.addRating(\"Buy\") // WORKS\n page.addRating(\"Sell\") // WORKS\n // *********\n page.addRating(\"Sell\") // FAILS! Can't find element with \"rating3\" name!\n // *********\n page = page.submit()\n WaitFor(\"rating to show up\", ()=&gt;page.asXml.contains(\"Sell\"))\n\n page.asText should include (\"Buy\")\n\n client.closeAllWindows()\n }\n}\n</code></pre>\n","tags":"java javascript html scala htmlunit"},"6395651":{"id":6395651,"title":"Is it possible to calculate sha256 hashes in the browser using the user's video card, eg. by using WebGL or Flash?","body":"<p>Is it possible to calculate sha256 hashes in the browser using the user's video card, eg. by using WebGL or Flash?</p>\n\n<p>I'm afraid this is all there is to ask, but if more elaboration is needed please do not hesitate to tell me in a comment.</p>\n\n<p>Thanks.</p>\n","tags":"javascript flash hash webgl sha256"},"6396782":{"id":6396782,"title":"Facebook style autocomplete using dojo needed.","body":"<p>I found facebook style autocomplete using jQuery. But im using dojo framework for my web app. Can you suggest how to implement or any open source code available for autocomplete using dojo framework. ?</p>\n\n<p>Using jquery :</p>\n\n<p><a href=\"http://devthought.com/wp-content/articles/autocompletelist/test.html\" rel=\"nofollow\">http://devthought.com/wp-content/articles/autocompletelist/test.html</a></p>\n","tags":"javascript autocomplete dojo jquery-autocomplete"},"6397574":{"id":6397574,"title":"How to access session in express, outside of the req?","body":"<p>I know that I can use </p>\n\n<pre><code>function(req, res) {\n req.session\n}\n</code></pre>\n\n<p>using express. However I need to access the session outside of the response function. How would I go about doing that?</p>\n\n<p>I'm using socket.io to pass information for adding posts and comments. So when I receive the socket.io message on the server-side, I need to verify the person posting the information by using the session. However since this is being done via socket.io there is no req/res.</p>\n","tags":"javascript node.js express socket.io"},"6398787":{"id":6398787,"title":"Javascript Shorthand for getElementById","body":"<p>Is there any shorthand for the JavaScript document.getElementById? Or is there any way I can define one? It gets repetitive retyping that <strong>over</strong> and <strong>over</strong>.</p>\n","tags":"javascript"},"6401696":{"id":6401696,"title":"javascript, what is this?","body":"<p>I have found this javascript code from instapaper's bookmarklet. </p>\n\n<p><strong>What exactly is this code doing?</strong></p>\n\n<pre><code>javascript:\nfunction%20iprl5(){\n var%20d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;\n try{\n if(!b)\n throw(0);\n d.title='(Saving...)%20'+d.title;\n z.setAttribute('src',l.protocol+'//www.instapaper.com/j/deyNbbpjuSei?u='+encodeURIComponent(l.href)+'&amp;t='+(new%20Date().getTime()));\n b.appendChild(z);\n }\n catch(e){\n alert('Please%20wait%20until%20the%20page%20has%20loaded.');\n }\n}\niprl5();\nvoid(0)\n</code></pre>\n\n<p>Thanks in advance!</p>\n","tags":"javascript"},"6401946":{"id":6401946,"title":"Prototyping Built-In Modules in NodeJS","body":"<p>I've been trying to add some convenience functions to Node's file system module (mainly because it lacks some common sense things), but every time I begin <code>fs.prototype.myfunc =</code> in the repl, Node complains that I am trying to set a property of an undefined variable. Is it really true that you cannot access Node's built-in module prototypes from the outside? If so, does anyone know a feasible workaround to extend Node's built-in modules?</p>\n\n<p>--Thanks! </p>\n\n<hr>\n\n<p>Just to note: I did require fs before trying to prototype it!</p>\n\n<pre><code>var fs = require('fs');\nfs.prototype.myfunc = function() {}; //TypeError thrown here\n</code></pre>\n","tags":"javascript node.js prototype"},"6403354":{"id":6403354,"title":"javascript : parsing multi-level json array","body":"<p>I have a asp.net web service that returns a multi-level array.</p>\n\n<p>the json string is parse using the json2.js lib :</p>\n\n<pre><code>var donnee = JSON.parse(msg.d);\n</code></pre>\n\n<p>the 1st level parsing is ok but the 2nd level array (data) remains as an array of objects</p>\n\n<blockquote>\n <p>? donnee[0]</p>\n</blockquote>\n\n<pre><code>{...}\ncolor: \"#0000CD\"\ndata: [[object Object],[object Object]]\nlabel: \"formol\"\ntype: \"traitement\"\n</code></pre>\n\n<blockquote>\n <p>? donnee[0].data</p>\n</blockquote>\n\n<pre><code>[[object Object],[object Object]]\n[0]: {...}\n[1]: {...}\n</code></pre>\n\n<blockquote>\n <p>? donnee[0].data[0]</p>\n</blockquote>\n\n<pre><code>{...}\n_l: \"\"\n_x: 7\n_y: 25\n</code></pre>\n\n<p>whereas I need an array of data e.g.</p>\n\n<blockquote>\n <p>? donnee[0]</p>\n</blockquote>\n\n<pre><code>{...}\nlabel: \"traitement formol 2\"\ntype: \"traitement\"\ncolor: \"#0000CD\"\ndata: [7,25,,7,40,formol]\n</code></pre>\n\n<blockquote>\n <p>? donnee[0].data</p>\n</blockquote>\n\n<pre><code>[7,25,,7,40,formol]\n[0]: [7,25,]\n[1]: [7,40,formol]\n</code></pre>\n\n<blockquote>\n <p>? donnee[0].data[0] </p>\n</blockquote>\n\n<pre><code>[7,25,]\n[0]: 7\n[1]: 25\n[2]: \"\"\n</code></pre>\n\n<p>what is the best way to decode/parse all the levels of the json string at once ?</p>\n\n<p>best regards</p>\n","tags":"javascript arrays json parsing"},"6403728":{"id":6403728,"title":"Set table cell width using Javascript - jQuery","body":"<p>I have a table as below;</p>\n\n<pre><code>&lt;table style=\"width: 100%\"&gt;\n&lt;tr&gt;\n&lt;td style=\"width: 30px\"&gt;cell&lt;/td&gt;\n&lt;td class=\"cell\"&gt;cell&lt;/td&gt;\n&lt;td class=\"cell\"&gt;cellcell&lt;/td&gt;\n&lt;td class=\"cell\"&gt;cellcellcell&lt;/td&gt;\n&lt;td class=\"cell\"&gt;cellcellcellcell&lt;/td&gt;\n&lt;td class=\"cell\"&gt;cellcellcellcellcell&lt;/td&gt;\n&lt;td class=\"cell\"&gt;cellcellcellcellcellcell&lt;/td&gt;\n&lt;td style=\"width: 30px\"&gt;cell&lt;/td&gt;\n&lt;/tr&gt;\n&lt;/table&gt;\n</code></pre>\n\n<p>The table is designed to stretch to screen (or a div having specific width). I want equal width for all cells having <code>class=\"cell\"</code> and this works well when the character length of text in all cells having <code>class=\"cell\"</code> are equal. But, I want to fix the cell width even if the character lengths of contents in <code>class=\"cell\"</code> are different. </p>\n\n<p>Also you can see that the first and last cells have fixed width, in <strong>pixels</strong> and others cell widths are to be calculated on the basis of percentage .. I want equal width for all cells (except first and last with fixed width in pixels).</p>\n\n<p>I think this can be done using <code>javascript</code> with the help of <code>jQuery</code>, by calculating the table cell widths on document ready, and then adding some function using <code>on window resize</code> and thereby calculating cell widths. The cell widths will be <code>(tablewidth in px - 60px)/6</code> I am a beginner and I don't know much.. How can i do this using jQuery and (or) javascript.</p>\n\n<p>It will be very helpful if someone make me a fiddle..</p>\n\n<p>Thanks in advance..</p>\n","tags":"javascript jquery"},"6404725":{"id":6404725,"title":"Google tasks update error","body":"<p>I am attempting to update a task with the following code:\n<br>\n<br></p>\n\n<pre><code>function updtsk(task,id)\n{\n var url = 'https://www.googleapis.com/tasks/v1/lists/@default/tasks/'+id;\n var req = {\n 'method': 'PUT',\n 'headers': {\n 'Content-type': 'application/json'\n },\n 'body': JSON.stringify(task)\n };\n var addDone = function(resp, xhr) {\n if (xhr.status != 200) {\n notifyFailure('Couldn\\'t update task.', xhr.status);\n return;\n }\n\n //notifySuccess(task['title']);\n }\n\n oauth.sendSignedRequest(url, addDone, req);\n}\n</code></pre>\n\n<p>I get the following error however:</p>\n\n<pre><code>\"{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"global\",\n \"reason\": \"invalid\",\n \"message\": \"Invalid Value\"\n }\n ],\n \"code\": 400,\n \"message\": \"Invalid Value\"\n }\n}\n\"\n</code></pre>\n\n<p>The update body is this:</p>\n\n<pre><code>{\n 'title': $(this).val()\n};\n</code></pre>\n\n<p>I am using the chrome_ex_oauth api and could use some help.</p>\n","tags":"javascript google-chrome-extension"},"6405964":{"id":6405964,"title":"Check if a String is HTML or XML","body":"<p>Is there a way to check if a String is HTML or XML in JavaScript? Preferably using jQuery rather than some other library?\nWhy I need to do this is because I need to know if it possible to have a function into which XML or HTML can be passed. If it is HTML we take one action and if it is XML we take another action.</p>\n","tags":"javascript jquery html xml check"},"6406161":{"id":6406161,"title":"JavaScript Encode","body":"<p>Surfing on web i find Ext.Gantt plugin for ExtJS, that extension have a special encode. Anybody know how to encode like that or another complicated form. </p>\n\n<p><a href=\"http://www.ext-scheduler.com/js/sch-gantt-all-debug.js\" rel=\"nofollow\">Encoded Gantt Chart</a></p>\n","tags":"javascript obfuscation decode encode ext"},"6409944":{"id":6409944,"title":"NowJS manually initiating a new connection after a lost connection","body":"<p>i have a case where clients connect to a node.js server running nowjs and remain connected for a fairly long time (about 30 minutes). on some browsers though the connection gets dropped after a while and the client disconnects.</p>\n\n<p>i implemented a disconnect handler on the client side like this:</p>\n\n<pre><code>now.core.on('disconnect', function () {\n // we should reconnect here, maybe after a short timeout\n});\n</code></pre>\n\n<p>what i am unclear about is how exactly to trigger a reconnect. this might be something blatantly obvious to experienced users but i didn't manage to figure this out.</p>\n\n<p>the now.js script initializes on page load and after that i can use the now object, but i can't figure out how to repeat this process without reloading the page.</p>\n\n<p>thanks!</p>\n","tags":"javascript node.js socket.io nowjs"},"6409972":{"id":6409972,"title":"How to dynamically set the grids CheckBox Selection Model in ExtJs4?","body":"<p>This leads on from <a href=\"http://stackoverflow.com/questions/6277991/reconfiguring-grid-columns-in-extjs4-selmodel-disappears\">my previous question</a>.<br>\nI initialize a grid with a CheckBox Selection Model, however when I reconfigure the grid the Check Box Selection Model visaully dissapears.<br>\nWhat I want to do is dynamically add a CheckBox Selection Model to a grid after reconfiguring the grids columns, and visually display it.</p>\n\n<p>I have tried something like this:</p>\n\n<pre><code>var sm = new Ext.selection.CheckboxModel();\ngrid.selModel = sm;\ngrid.doLayout();\n</code></pre>\n","tags":"javascript extjs grid columns extjs4"},"6410184":{"id":6410184,"title":"jQuery.find().each(fn) is not working in Firefox","body":"<p>I have AJAX call to one XML file and the source code is given below. It works perfectly in Chrome but is not working in Firefox. When doing debug I see that it doesn't enter to the cycle of $(response).find(\"simpleType\").each(function() in Firefox. </p>\n\n<p>Does anybody know what is the problem here in my code?</p>\n\n<pre><code>$.ajax({\n type:\"GET\",\n url:\"views/workspace/branching_forms/StudentModelDescription.xml\",\n dataType:\"xml\",\n error:function(XMLHttpRequest, textStatus, errorThrown){\n alert(\"error=\"+XMLHttpRequest+\" error2=\"+textStatus+\" error3=\"+errorThrown);\n },\n success:function(response){ \n var i=1;\n console.log(\"response=\"+response);\n $(response).find(\"simpleType\").each(function(){ \n adaptation_type_name[i]=$.trim($(this).find(\"documentation\").text()); \n var restriction = $(this).find(\"restriction[base=xs:string]\");\n j=1;\n var values=new Array(); \n $(restriction).find(\"enumeration\").each(function(){\n var tmp=$(this).attr(\"value\"); \n values[j] = tmp;\n j++;\n });\n adaptation_type_variables[i]=values; \n console.log(\"adaptation_type_name=\"+adaptation_type_name[i]+\", adaptation_type_variables=\"+adaptation_type_variables[i]);\n i++; \n }); \n for(var i=1;i&lt;=adaptation_type_name.length;i++) \n $('#adaptation_type_dialog #branching_adaptation_type').append($(\"&lt;option&gt;&lt;/option&gt;\").attr(\"value\",i).text(adaptation_type_name[i]));\n\n }\n});\n</code></pre>\n\n<p>The content of StudentModelDescription.xml is given below:</p>\n\n<pre><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"&gt;\n &lt;xs:simpleType name=\"browser\" id=\"context_browser\"&gt;\n &lt;xs:annotation&gt;\n &lt;xs:documentation xml:lang=\"en\"&gt;Web Browser&lt;/xs:documentation&gt;\n &lt;/xs:annotation&gt;\n &lt;xs:restriction base=\"xs:string\"&gt;\n &lt;xs:enumeration value=\"Safari\" id=\"1\" /&gt;\n &lt;xs:enumeration value=\"Google Chrome\" id=\"2\" /&gt;\n &lt;xs:enumeration value=\"Opera\" id=\"3\" /&gt;\n &lt;xs:enumeration value=\"Mozilla Firefox\" id=\"4\" /&gt;\n &lt;xs:enumeration value=\"Internet Explorer\" id=\"5\" /&gt;\n &lt;/xs:restriction&gt;\n &lt;/xs:simpleType&gt; \n &lt;xs:simpleType name=\"networktype\" id=\"context_networktype\"&gt;\n &lt;xs:annotation&gt;\n &lt;xs:documentation xml:lang=\"en\"&gt;Network Type&lt;/xs:documentation&gt;\n &lt;/xs:annotation&gt;\n &lt;xs:restriction base=\"xs:string\"&gt;\n &lt;xs:enumeration value=\"ADSL2+/Cable (High capacity)\" id=\"1\" /&gt;\n &lt;xs:enumeration value=\"ADSL / HSPA (Moderate capacity)\" id=\"2\" /&gt;\n &lt;xs:enumeration value=\"Dialup / GPRS (Low capacity)\" id=\"3\" /&gt;\n &lt;/xs:restriction&gt;\n &lt;/xs:simpleType&gt;\n&lt;/xs:schema&gt;\n</code></pre>\n","tags":"javascript jquery xml firefox"},"6410224":{"id":6410224,"title":"to get value from database table into select box","body":"<p>i m creating a combo box which gets value from mysql database table.\n here is a sample code which i m implementing but it will not populates selectbox values.</p>\n\n<pre><code> mydata +='&lt;div class=\"content nodisplay\"&gt;&lt;div class=\"row\"&gt;&lt;div class=\"label\" style=\"font-size:22px;\"&gt;Subject&lt;/div&gt;&lt;div class=\"data\"&gt;\n&lt;select id=\"fillsubject\" name=\"fillsubject\"&gt;';\n$.post(document.URL,qstring,function(data){\n\n var subjects = $(data).filter('.subjects');\n\n $.each(subjects,function(index,value){\n var subid = $(this).attr('id');\n var subname = $(this).text();\n mydata += \"&lt;option value='\"+subid+\"'&gt;\"+subname+\"&lt;/option&gt;\";\n //mydata += \"&lt;option value='english'&gt;english&lt;/option&gt;\";\n });\n\n});\nmydata +='&lt;/select&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;'; \n</code></pre>\n","tags":"javascript mysql php5"},"6411169":{"id":6411169,"title":"Javascript replace undefined error ends but not replace continues","body":"<p>Friends i got success with this piece of code:</p>\n\n<pre><code>var avidno = '800.123.1234';\nvar bodytext = document.body.innerHTML;\nvar newbodytext;\nfunction validate () {\nvar regex = /^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;\n\nif (regex.test(avidno)) {\n alert('bingo');\n var avidno_new = '&lt;span&gt;'+avidno+'&lt;/span&gt;';\n var newbodytext = bodytext.replace(new RegExp(avidno, \"g\"), avidno_new);\n document.body.innerHTML = newbodytext;\n // Valid international phone number\n} else {\n alert('uupss');\n // Invalid international phone number\n}\n}\nvalidate();\n</code></pre>\n","tags":"javascript html replace body"},"6411194":{"id":6411194,"title":"Jquery plugin - Tree Context menu","body":"<p>Can you suggest a context-menu plugin that supports nesting menu items? When clicking on an item, if the item has sub-items, it should open a secondary menu.</p>\n\n<p><strong>EDIT</strong></p>\n\n<p>Like <a href=\"http://www.contextmenu.net/screenshot/screenshot_windows_explorer_shell_context_menu.jpg\" rel=\"nofollow\">this</a> but for jquery</p>\n","tags":"javascript jquery plugins"},"6411282":{"id":6411282,"title":"How to lock scrolling of a web page temporarily?","body":"<p>How can I lock scrolling of a webpage temporarily when a dialog box is displayed ? I have a dialog box within which I want to enable scrolling <strong>after deactivating scrolling from the overlayed webpage</strong>. </p>\n\n<p><strong>Is there a js command to <em>temporarily</em> disable scrolling ?</strong></p>\n","tags":"javascript html"},"6411574":{"id":6411574,"title":"Resources that turns a javascript developer into a great javascript developer ?","body":"<p>I am more and more working with javascript, especially with JQuery for web site and node.js for server side (really like node.js though) and I quite often struggle to understand the inner structure of the language (such as prototypes, asynchronous function, ...). </p>\n\n<p>What are the best articles, or so, that could help a developer to leverage his competency in this language (that is really worth learning IMHO).</p>\n","tags":"javascript"},"6411636":{"id":6411636,"title":"Javascript slider problem","body":"<p>Hi I am currently working on a script given to me by my boss and it is not working in all browsers except IE.</p>\n\n<p>Now he is using the CSS property left to animate it so he has a variable which gets the current value of left. For example lets say left is equal to <code>-100px</code>.</p>\n\n<p>Now once it has this value it adds <code>10px</code> onto the value to make it move in from the left.</p>\n\n<p>Now my issue lies with <code>parseInt()</code> and the <code>\"px\"</code> prefix at the end of the number. it keeps returning <code>NaN</code> instead of the value of left.</p>\n\n<p>Does anyone know how to fix this problem?</p>\n\n<p>Thanks in advance</p>\n","tags":"javascript css nan parseint"},"6411637":{"id":6411637,"title":"Javascript count number of steps","body":"<p>How can I count number of steps between different numbers.</p>\n\n<p>I have a method that takes a number and runs a code snippet with the number. I need to see if the number is the number right next to the other or two steps, three steps, four steps over or below etc.</p>\n\n<p>Ex. I send a number of 1 to the method. The next number sent is 4. I then need to find out how many steps over one it is etc in this case 3 steps over 1 should be the result.</p>\n\n<p>Any clues? </p>\n","tags":"javascript count script"},"6411778":{"id":6411778,"title":"Rails 3 plugin nested_form versus JavaScript appraoch for adding form fields dynamically in a nested form","body":"<p>I am researching ways on how to dynamically add form fields for nested models and stumbled accross the <a href=\"https://github.com/ryanb/nested_form\" rel=\"nofollow\">nested_form</a> plugin by ryanb. No doubt this is a a great piece of code, but I wondered why does it have to be so sophisticated?</p>\n\n<p>Example: A form for creating / adding a project has one or more tasks assigned. The user can dynamically add more tasks by clicking on a add-task button. A project must have at least one task. Each task has a name and a description.</p>\n\n<p>So why not just:\n- When generating the html, sourround each set of task fields with a div given an ID such as \"dynamic_fields\"\n- When the user clicks the add-task button, call a JavaScript function via link_to_function to clone the dynamic_fields subtree. Insert the new set of fields at the bottom of the task list.\n- Via JavaScript, remove the values of the newly added fields and replace the child ID with something unique (Ryan suggests using a value based on the current time)</p>\n\n<p>I am aware that the nested_forms plugin also works for deeper nesting structures, but given my simple use case with only one level of hierarchy, is the approach outlined above practical? Or am I missing something important? Any guidance on this topic is appreciated. </p>\n","tags":"javascript ruby-on-rails nested-forms"},"6411964":{"id":6411964,"title":"Should I rely on externally-hosted services?","body":"<p>I am wondering over the dangers / difficulties in using external services like <a href=\"http://code.google.com/apis/chart/\" rel=\"nofollow\">Google Chart</a> in my production state website.</p>\n\n<p>With external services I mean them that you can't download and host on your own server.</p>\n\n<p><strong>(-)</strong> Potentially the Google service can be down when my site is up.</p>\n\n<p><strong>(+)</strong> I don't have to develop those particular systems for new browser technologies, hopefully Google will do that for m