javascript

What is a good example for functional style web programming using javascript?

I'm doing javascript on a daily basis at the moment. I'm coming from an OO background and most of the code I have contact with is somewhat procedural/OO style. I'm looking for good examples that solves more or less typical web programming tasks but in a functional manner. I'm not interested to have any arbitrary example that just looks ...

Javascript multiple replace

How do you replace all instances of one string with another in javascript? Example: someString = 'the cat looks like a cat' anotherString = someString.replace('cat', 'dog'); results in anotherString being set to 'the dog looks like a cat', and I would like it to be 'the dog looks like a dog' ...

PHP Form code mangled

I am generating a simple form with php. The following code has been reduced to showcase the problem. <?php $blah = "<h1>Well</h1>"; $test = "<h2>Done</h2>"; echo '<script type="text/javascript" src="fetchlayers.js"></script>'; $formcode = "<form action=\"process.php\" method=\"post\" enctype=\"multipart/form-data \">" . "<labe...

Saving the order of a list (php/zend/jquery)

I'm using the jQuery library to have an ordered list with the ability to re-order items with drag and drop. I want to send the information of the order to the database and the next time you refresh the page (or load it on another browser/computer) it would have your order. I have a table for each element of the list in mySQL and right n...

Rails: How can I log on which site my javascript is embedded?

My site provides a javascript that shows the rate of the Dutch equivalent of the Dow Jones index. Users can embed this script in their website. It looks like this: <script type="text/javascript" src="http://www.aexscript.nl/r/gratis"&gt;&lt;/script&gt; The corresponding controller action looks like this: def show @script = Script....

missing ) after argument list in html form code

I am trying to use the following code, to display $formcode, which is the html code for a form, in a popup windows. I understand that it is not an ideal method, but I want to understand why it is not working. <?php $blah = "Well"; $test = "Done"; echo '<script type="text/javascript" src="fetchlayers.js"></script>'; $formcode = "<form ac...

[JavaScript] How to check if Google Maps is fully loaded ?

I've embedding Google Maps on my web site. Once Google Maps is loaded, I need to kick off a few JavaScript processes. Is there a way to auto-detect when Google Maps has fully loaded ... including tile downloads and all? A tilesloaded() method exists that is suppose to accomplish exactly this task but it does not work. Thanks in advanc...

Having a delayed action after clicking a form

I have the following code to open a form in a popup window. I want to, after clicking the submit button, have an alert popup after 1250 milliseconds. This does not currently work as the page gets redirected to the result of submitting the form. <?php $blah = "Well"; $test = "Done"; echo '<script type="text/javascript" src="fetchlayers.j...

Numbers with commas in Javascript

I have a javascript function that accepts a number and performs a mathematical operation on the number. However, the number I'm passing in could have a comma in it, and from my limited experience with Javascript I am having problems working with that value. It doesn't seem to treat that as a numeric type. What's the easiest was to tak...

How to scroll the window using JQuery $.scrollTo() function

Hi, I'm trying to scroll down 100px every time the user gets near the top of the document. I have the function executing when the user gets close to the top of the document, but the .scrollTo function isn't working. I put an alert after and before to check to see if it actually was the line or not that was stopping it and only the fir...

Creating simple bookmarklet in javascript

Hi, I'm trying to pick up the selected text of a document in a bookmarklet. How do I implement this? I got this from the internet. Why does this not work? javascript: Q=document.selection?document.selection.createRange().text:document.getSelection(); alert(Q); Thanks! ...

How to validate a file upload field using Javascript/jquery

How can I validate if the user has selected a file to upload? Edit: bumped ...

Does execCommand SaveAs work in firefox?

Why does this not work in ff/chrome? javascript: document.execCommand('SaveAs','true','http://www.google.com'); (used as a bookmarklet) ...

submit is not a function in javascript

Does anyone can tell me what is going wrong with this code? I tried to submit a form with javascript, but error ".submit is not a function" shown. See below for more details of the code: <form action="product.php" method="get" name="frmProduct" id="frmProduct" enctype="multipart/form-data"> <input onclick="submitAction()" id="submit_va...

How to force save as dialog box in firefox besides changing headers?

Is there a way to force a save as dialog box for www.example.com/example.pdf in ff? (i can't change the headers) ...

Why is this piece of Javascript code so slow?

I have this piece of Javascript code, which takes about 600 ms on every call in Internet Explorer. The time taken in other browsers is negligble. var _nvs_currentTab; var _nvs_zoomfield; var _nvs_centerfield; var _nvs_globsearch; var _nvs_category; var _nvs_favsonly; var _nvs_wishonly; var _nvs_friendfavsonly; var _nvs_newitemsonly; var...

What is the difference between 'undefined' and 'not defined'?

If you attempt to use a variable that does not exist and has not been declared, javascript will throw an error. var name is not defined, and the script will stop then and there. But if you check it using typeof noname then it will return "undefined". I always thought that you had to declare a var for it to have a type. Either by using: ...

clientHeight/clientWidth returning different values on different browsers

The properties: document.body.clientHeight, document.body.clientWidth return different values on IE7, IE8 and Firefox: IE 8: document.body.clientHeight : 704 document.body.clientWidth : 1148 IE 7: document.body.clientHeight : 704 document.body.clientWidth : 1132 FireFox: document.body.clientHeight : 620 document.body.clientWidth : ...

end date greater than start date - jquery validation

how do i check/validate in jquery whether end date [textbox] is greater than start date [textbox]? ...

JSONobject to JSONtext

how can i convert a JSON Object to JSONtext in a javascript function. i should pass the JSONtext as a string to JSP. ...