javascript

How to cast a php array into javascript array

I run a mysql query and get the results successfully. However, I cannot read the elements of the array from javascript side. Can anyone help?? //JAVASCRIPT makes a request function profiles(){ $.post('dbConn.php', { opType:"getProfileList" }, fillProfileCombo, "text"); } function fillProfileCombo(res) { alert(res); } //dbConn.php...

Help with Submit form. Loading results into content div.

Hi everyone, I'm using this tab script from Dynamic Drive. Here's the URL... http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/index.htm I have a page which has a search form for friends. When submitted I'd like the results to load into the content container.."countrydivcontainer" Basically here's my layout... <table cellpa...

How to write a factorial function in Javascript using setTimeout or setInterval

Hi all, I asked a question a couple weeks ago about using setTimeout for a factorial function, but it was unfortunately with an unregistered account and I never got a complete answer. My main issue is that I'd like to write a function that calculates the factorial of a number but uses the setTimeout or setInterval commands. The impetu...

Javascript: Re-assigning a function with another function

Let's say I have these two functions: function fnChanger(fn) { fn = function() { sys.print('Changed!'); } } function foo() { sys.print('Unchanged'); } Now, if I call foo(), I see Unchanged, as expected. However, if I call fnChanger first, I still see Unchanged: fnChanger(foo); foo(); //Unchanged Now, I assume this is becaus...

Recording website load times?

I am trying to record the time it takes to load my website on an average (say 10 runs) from various locations in the world. For this, I was thinking of using a list of proxies to achieve this and am not sure this is the perfect way of doing this. Is there a Firefox add-on that lets me time this perhaps using Firebug itself? Is there a...

JS - Get all LI elements in array

How can i make JS select every LI element inside a UL tag and put them into an array? <div id="navbar"> <ul> <li id="navbar-One">One</li ><li id="navbar-Two">Two</li ><li id="navbar-Three">Three</li ><li id="navbar-Four">Four</li ><li id="navbar-Five">Five</li> ...

Referring to "this" in a parent closure in javascript

I want to do this in Javascript: function Z( f ) { f(); } function A() { this.b = function() { Z( function () { this.c() } ); } this.c = function() { alert('hello world!'); } } var foo = new A(); foo.b(); It can be accomplished this way: function Z( f ) { f(); } function A() { var self = this; this.b =...

Javascript: Image to Base64?

Is there any way how to encode a png/jpeg/gif image to base64 using Javascript (can't use canvas toDataURL)? Thank you. ...

JavaScript, v8, and function printing

In node.js (or v8/chrome), can I rely on using string concatenation for getting the code behind a function? for instance, in node.js var f = function(x) { return x; } console.log(f); shows "[Function]" while console.log("" + f); shows "function(x) { return x;}" is this a reliable semantic? Is this in the ECMA spec somewhere? ...

Simple Tab Javascript Sections (not menus)

This might be the simplest question of the day. I'm looking for the best answer based on all knowledged across community, not a basic tab effect but one that could be scalable, easy to implement and compliant with standards. What could be a good and simple (compatible) way to accomplish having different sections with javascript. I pers...

How do I reload the page after all ajax calls complete?

The first time a user is visiting my website, I am pulling a lot of information from various sources using a couple of ajax calls. How do I reload the page once the ajax calls are done? if(userVisit != 1) { // First time visitor populateData(); } function populateData() { $.ajax({ url: "server.php", data:...

Best way to build a Javascript Array of Objects on Ruby on Rails

I have this but I'm pretty sure that is not the best way to build it up. var dogs = { 'names' : ["a", "b", "c"], 'images': [ <% @dogs.images.each do |image| %> { 'thumb' : '<%= image.thumb %>', 'medium' : '<%= image.medium %>', } <%= "," unless(@dogs.images.last.id == image.id) %> <% end %> ] } Thanks for your he...

Print values of selected radio buttons and check-boxes and exclude the submit button

In the script below, how do I get the values of only radio buttons and checkboxes that have been selected and not all (provided a radio button and checkbox were selected). Right now it gives me the values of all, whether selected or not, and also the submit button (which i dont need). How do i do this? There'll be more checkboxes and...

IE7 - <button> does not submit form

hello, How can I make a tag in IE7 submit the form, while doing all the form validation that is setup on the form? if I just do a document.forms[0].submit(); it submits, but ignores form validation. Edit: Everybody likes telling me to use the input tag... That will sumbit the form but wont work in my situation which is why i asked ab...

Go to anchor without changing url

On loading a page I would like it to go to #content without changing the url. I thought I would be able to use window.location.hash = "content"; window.location.replace("#content", ""); but #content still exists on the url. Any better method? Edit: Also tried window.location.hash = "content"; window.location.replace(window.loca...

what language do i use to write a webpage in to automatically update from a database of sorts?

Hey Guys and Gals, I have what I consider a bit of a tricky question. I am currently working on quite a large spread sheet (266 rows aith 70 coloumns and its only going to get bigger) that is a database of sorts and I want to remove it from Excel and put it on to an intranet page. I am currently writing it in a combination of HTML and ...

JS - Object expected on new object();

What am i doing wrong here? var navbar = document.getElementById("navbar").getElementsByTagName("li"); var hover; var moname; var slider; var newPos=new Object(); var body=document.getElementsByTagName('body')[0]; for (x in navbar) { if (x != 'length') { moname=(x+"-mo"); hover...

Why can only my most recently added page element be resized?

I have a webpage where I can click on it to add a image. If I then click on the image it makes it bigger and if I click again it resizes it back to the original size. If I then click somewhere else on the screen I can create another image and grow and shrink this also by clicking on it. The problem is only the latest image can be resized...

javascript :: date formatting?

Hi guys I am using an api with a json endpoint to grab some data. the api returns dates that look like: Date(1288205847730) (so a basic javascript date object) How do I convert that to Thu, 28 Oct That is the generalized question that I could work from. The actual question is I want to show Thu, 28 Oct format if there is more than 2...

Prefix of my domain is messing things up... How do I resolve this?

I am writing a Facebook app and for it to work properly, I need to set the Site URL inside the Application settings. The problem is that if I set my Site URL to be domain.com it works on my system and a bunch of systems that I tested it on. Some of my friends complain that it is not working on their system. When I looked at what the er...