javascript

How do I write selected jQuery DOM elements back out as XHTML snippets?

I'm wanting to select some DOM elements using jQuery, modify some attributes, and then write the DOM elements back out as xhtml snippets for post processing. I want the resulting xHTML to have only the attributes specified in the original page html plus the modifications I make with jQuery. Is there an existing javascript library or AP...

problems with modal window/background

Hi, I'm trying to make modal window for my website, I have a problem with overlay or modal div I'm not sure what is the problem. The thing is everything except modal window shouldn't be clickable, but for some reason my navigation <ul><li> tags are visible and clickable. Here is css of my modal window : element.style { display:block; ...

In javascript, is accessing 'window.Math' slower or faster than accessing the 'Math' object without the 'window.'?

I'm kind of curious about what the best practice is when referencing the 'global' namespace in javascript, which is merely a shortcut to the window object (or vice versia depending on how you look at it). I want to know if: var answer = Math.floor(value); is better or worse than: var answer = window.Math.floor(value); Is one bette...

How to programmatically set the value of a WebKit password text field?

Update: this question is bunk. Move along, nothing to see here. You can set the value of the password text field from either JS or ObjC. I was wrong. I have a WebKit-based Cocoa app which loads an HTML document containing an HTML form in a WebView. The HTML form contains a password text field like: <form name="foo"> <input type="pa...

getElementById().value returns nothing

<td id="'.$row['id'].'"style="display: none;"> <input id="addEdit" type="text" value="" size="4"/> </td> <td> <input name="add" value="A" type="submit" onClick="addObs('.$row['id'].'); return false;"/> </td> . function addObs(id) { var addEditTD = document.getElementById(id); if (addEditTD != null && addEditTD.style.d...

Allocating a char buffer with JNA, Rhino, JavaScript

In Narwhal, we are using JNA to make libc calls like getcwd and chdir. I've only been able to use this with my limited knowledge of the JNA interface as it pertains to JavaScript in Rhino, dealing exclusively with primitives. I need to know how to allocate a char buffer so I can pass it to getcwd, retrieve a JavaScript String from that...

World time clock with DST support and server sync

I want to include a JavaScript world time clock like http://www.dynamicdrive.com/dynamicindex6/localtime.htm to my homepage but I don't want to change it every time when the DST changes for a time zone. Is it possible to sync it automatically with an official time server so that I can display the current time for different places live an...

How to get class names?

Hey, I am trying to get the class names dynamically for the script below. I have different class names that are created through PHP so need to get them using jQuery dynamically. As you can see below, there seems to be 2 areas where I need to get the class name. At the moment it is hard coded (the classes are named 'result'): 1) var ne...

ASP.Net RegularExpression Validator - Parsing bug

I wanted to write a regular expression using the ASP.Net RegExp validator that would ensure a field contains only numeric and decimal values, and at least one character. ^[0-9]{1,40}(\.[0-9]{1,2})?$ Essentially: [0-9]{1,40} - meaning at least one to 40 numeric characters. The ASP.Net regexp validator does not fire for an empty field ...

How to make Visual Studio stop "compiling" .js and .css files

I use Visual Studio as my editor for .css and .js files.. It REALLY SUCKS especially with .js files since it insists on indenting them in a very weird way, but I find it convenient that the first alt-tab is always the browser instead of another editor, and that ctrl-tab is always either the code file or the css/js. Anyways, in all its r...

Adding SVG element to an html file?

Hi, I'd like to add some SVG elements to an html file. I'm finding links which say this is not supported, the document type must be xhtml. But I am using some javascript libraries with html that allow me to use SVG in them (Raphael, SVG Web, etc). So is there a way to add a script to an html file which can dynamically add an SVG eleme...

Explanation of [].slice.call in javascript?

I stumbled onto this neat shortcut for converting a DOM NodeList into a regular array, but I must admit, I don't completely understand how it works: [].slice.call(document.querySelectorAll('a'), 0) So it starts with an empty array [], then slice is used to convert the result of call to a new array yeah? The bit I don't understand is ...

javascript trunc() function

I want to truncate a number in javascript trunc(2.6)==2 ...

array join() method with a separator

var arr= ['g','o','o','d']; var arr2 = arr.join(); Arr2 will be "g,o,o,d". I would like to get "good". I know there are a million other ways to achieve this but was curious if there was a way with join. Thanks ...

Setting document.body.className as a variable

This is my code to switch the class of my body tag when a user clicks a link. function switchBodyColor() { if (document.body.className == 'blue') document.body.className = 'red'; else if (document.body.className == 'red') document.body.className = 'green'; else if (document.body.className == 'green') ...

onComplete for Ajax.Request buggy with cached content

I have a Ajax.Request in which I use onLoading and onComplete to show and hide a load animation gif. The problem is that every 10 clicks or so, the load animation fails to hide and just stays there animating even though the ajax request has returned successfully. I have a number of div elements that each has its own respective load anim...

Javascript: how to change form fields value with single click

Hi all, I'm trying to set the value of three different input text fields with an onclick function. I have an image that has this code... <img src="images/delete_row.png" width="25" onClick="clearRow(0);" /> And I have three input text fields that all have the id of "0". When I click my image I want to set the value of all three fie...

Prototype Toggle through Array Only Toggling Last Item

I'm a beginner and my brother has showed me some prototype. All the weeks successfully toggle the last week in the array but no other. Please let me know if I need to be more specific! Thanks! <%= @athletic_program.program_name %> <br> <br> <% array of_ids = Array.new %> <% @program_weeks.each do |program_week| %> <% array_of_ids...

Odd DOM Problem with Firefox

Hello. I'm experiencing an odd problem when trying to navigate through a table's rows and cells in a while loop using javascript. I'm using Firefox 3.5.7 on Win7 with Firebug enabled. I have this markup: <table> <tbody> <tr id='firstRow'><td>a</td><td>b</td><td>c</td></tr> <tr><td>a</td><td>b</td><td>c</td></tr> ...

Webkit: Key Undefined in Storage Event

I've been trying to set up a storage listener, similar to the one seen here: http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html#//apple_ref/doc/uid/TP40007256-CH6-SW6 However, when a set a value like so: localStorage.setItem('hello', 'world'); or ev...