Posts Tagged ‘javascript’

Use Javascript to Parse a Query String

Tuesday, March 4th, 2008

Most server-side scripting languages, like PHP, come with built-in functionality for reading query strings. Javascript doesn’t have any kind of standard counterpart, but that doesn’t mean you can’t use query strings in Javascript.

With some String functions, you can create your own function to parse a query string attached to the request url and store it in an associative array – just like PHP would for you.
(more…)

How to Randomize AdSense Ads with Javascript

Friday, February 29th, 2008

I came across this problem on the forums today. How can you randomize which Ad Sense ad to show using Javascript?

The solution, it turns out, is very simple.
(more…)

Javascript Function: Random Number Generator

Sunday, February 24th, 2008

Yesterday, I wrote a short article on generating random numbers in Javascript. The Javascript random number generator is similar to C/++ – it gives you a random number from 0 to 1 and you need to make it useful.

At the suggestion of a reader (thanks Justin), I decided to go ahead and turn the general formula for this into a short helper function to generate a random number.
(more…)

How to Create a Random Number in Javascript

Saturday, February 23rd, 2008

I’ve been working with PHP for some time now, and I’ve become spoiled with the rand() function for generating random numbers. It’s so simple – pass a min, pass a max, and get the number you want.

While I was working on various game-related scripts this weekend, I was left wondering how to create a random number in Javascript. It’s not quite as simple as the rand() function – we’ll have to go back to the old C-style random number generation.
(more…)

Javascript Game Spotlight: 3d Worm

Saturday, February 23rd, 2008

Screenshot of a 3d Worm game written in Javascript.I was browsing the Frihost forums this morning, and I stumbled on a cool Javascript game.

One of the Frihost users and his friend made a 3d Worm game. Although the directions are in Spanish (as is the source code), the game is pretty cool. It’s a good example of what you can accomplish with some Javascript/DOM trickery.
(more…)

Javascript Strings: How to Do String Replacement in JS

Friday, February 22nd, 2008

This morning I set about making a simple script to clean extra newline characters out of text. I could easily have processed the form contents in PHP, but I wanted to use Javascript to avoid reloading the page.

The concept seemed simple enough, but I ran into a problem – I didn’t know how to do string replacement in Javascript. The first thing I thought was, “What is the Javascript equivalent to str_replace?”
(more…)

Text Cleaner – Remove Newlines from Text and Articles

Friday, February 22nd, 2008

Do you have a bunch of old articles stored on your computer with hard linebreaks?

These newline characters make it a real pain to upload your articles to your own site through a CMS or to article submission directories. They want free-flowing text that gets broken up automatically by the browser.

If you need to get rid of these newline characters, use the Text Cleaner form below. It works very simply.

Copy and paste your article with newline characters into the top textarea box. Click the button. Copy and paste the cleaned text out of the lower box.

Note: The text cleaner preserves a sequence of “\n\n.” It is assumed that these double newline characters are paragraph breaks, and removing them would make the article illegible.


Text Cleaner Tool: Remove Newline Characters




Great Resources: Learning JS, AJAX, and DOM

Tuesday, February 19th, 2008

Over the weekend, I decided it was finally time to learn how to use JS and AJAX. I’d deliberately avoided using JS for anything I could accomplish in PHP – but I admit that I was getting a bit intrigued by the AJAX hooplah.

I found some very useful resources for dealing with JS, AJAX, and DOM, so I thought I’d share them for any other eager learners.
(more…)