In this reference article we’ll explain what strings are, why they’re important, and how they work in JavaScript. We’ll cover all the properties and methods of strings, along with some simple examples.
java script
Preventing Multiple Form Submits
Forms on websites are a handy way to get information from your visitors. However it’s easy for a visitor to accidentally send more than one copy of a form by clicking on the form’s “submit” button more than once. The end result can be that identical emails get sent to the Webmaster, or identical records get added to a database.
This handy little tutorial shows how you can use JavaScript in your Web pages to avoid forms being submitted more than once by a visitor.
Fun with Random Numbers
We can use JavaScript to generate random numbers, that is, numbers that are different each time the script is run. This allows us to do all sorts of fun stuff, such as:
- Show a random image or piece of text on the page
- Make a link that links to a random page
- Create games that people can play in their browser
First, let’s look at how we can create a random number in JavaScript.
[Read more…] about Fun with Random Numbers
Working with Dates
JavaScript’s Date
object makes it easy to handle dates in JavaScript. You can use this object to store dates, convert between date formats, and retrieve the current date and time.
In this tutorial we’ll take a look at using the Date
object, and end with a simple example script that displays the current date on the web page!
JavaScript and Cookies
A great feature of JavaScript is that it lets you set and retrieve browser cookies. In this tutorial I’ll show you how this is done, along with a simple example that remembers your name and displays it on every page.
Controlling Program Flow in JavaScript
One of the key features of all good programming languages is the ability to control the order in which actions are performed. For instance, you may want to run one piece of code if the user has selected a checkbox, but run a different piece of code if they haven’t selected it. Or, you may want to run the same piece of code 10 times (for example, if you’re creating a drop-down list with 10 items).
In this tutorial you’ll learn how to write code to make decisions (e.g. “if the user has selected this checkbox, display this message”), and perform the same action many times (called “looping”).
JavaScript Events and Event Handlers
In this tutorial we’re going to take a look at a very handy feature of JavaScript called events. By writing code that reacts to events, you can make your web pages much more interactive!
Read on to find out how…
Form Validation with JavaScript
This tutorial will show you how to create a JavaScript-enabled form that checks whether a user has filled in the form correctly before it’s sent to the server. This is called form validation. First we’ll explain why form validation is a useful thing, and then build up a simple example form, explaining things as we go along. At the end, there’s a little exercise to keep you busy too!
Rollover Buttons with JavaScript
These days every man and his dog is using JavaScript to create “rollover”, or “mouse-sensitive” buttons on their site. If you’re not sure what I’m talking about, move your mouse over this baby:
Get the idea?
[Read more…] about Rollover Buttons with JavaScript
Opening Windows with JavaScript
One of the most useful (and quite possibly the most abused) features of JavaScript is its ability to manipulate browser windows. It can be very handy for creating a pop-up navigation.
Multiple pop-up windows can be a real pain, especially now that certain free web space companies are getting in on the act as a method of advertising, so go easy on them. A good rule of thumb is: if you’re opening two new windows, you’re opening one too many!