Although you can put embedded programming in a webpage via a number of different methods, they are all the realm of the programmer. And that’s not much fun for us non-programmers. So I will focus on the easiest way to embed programming into a webpage. That’s JavaScript. It’s the hidden magic of webpages.
First, let’s discuss what JavaScript is. JavaScript can do a lot of things, but it’s not a full-fledged programming language. Chances are it will do almost anything you want to do, but it has its limitations.
Second, JavaScript is an easy language to learn, and almost every programmer can use it. Therefore, there’s a lot of competition among independent programmers to get JavaScript business. What this means to you is that you can get JavaScript programming done inexpensively. Plenty of freelance programmers are ready to go to work for you.
JavaScript is not the same as Java. JavaScript is a simple scripting language that a programmer uses to create functionality in webpages. It runs in the browser. On the other hand, Java is a full-fledged programming language designed to work in webpages and also in other online formats. When you need to do something beyond JavaScript’s capability, one of your choices is to program it in Java. But don’t get the two mixed up. JavaScript is easy and inexpensive to create. Java is more complex and more expensive. It all depends what you need to do.
If you have something really complex that you want to program and embed in a webpage, you’ll have to hire a programmer to program it in Java or a full-fledged programming language. This is typically a major programming project and a significant expense. To get advice on what you need, consult a programmer who specializes in web work.
The question is, what’s simple and what’s complex? Calculations are very simple for a programmer to write. It’s the interface (the presentation) that requires a lot of programming. This might be counter-intuitive.
For example, calculating what your cost of owning a car for five years takes into account (1) purchase price, (2) sale price, (3) loan expenses, (4) repairs, (5) routine maintenance, (6) insurance, (7) gas, (8) tolls, (9) license fees, (10) parking expense, and (11) depreciation; that’s much easier to program than programming the format to display such calculations. Consequently, if you can keep the interface of your embedded program simple, it will keep your programming costs lower.
A significant question (and a question that should command your attention) is, what can you do with JavaScript without a programmer? There are thousands of JavaScripts out there somewhere. If you can find one that suites your purpose, why reinvent the wheel? Use a JavaScript that’s already been written to embed into your webpage.
You will find such JavaScripts available as freeware and ones that you can use royalty-free (you pay once to use forever without additional payment). Pretend you’re Sherlock Holmes; sit down at your computer; open your browser; and go to work with Google (or your other favorite search engine). You might be surprised what JavaScripts you can find.
Another way to find JavaScripts is to just fine something that someone has embedded in a webpage that you like. Approach the webmaster to find out whether you can obtain and use the same JavaScript (the same embedded programming). The worst that can happen is that the webmaster will say no. But no won’t always be the answer to your question.
But I’ve saved the best for last. There are conversion programs that enable you to create a JavaScript program using software with which you can become proficient. For instance, if you can use an Excel spreadsheet, you can create any kind of calculator or numbers cruncher. There are conversion programs that will convert Excel spreadsheets into JavaScript spreadsheets you can embed in webpages. Users employ such spreadsheets or calculators (right in a webpage) to do calculations.
Want to teach people how to do a profit and loss statement? Build one in Excel, convert it to JavaScript, and embed it in a webpage. Your webpage users will be able to plug in their own numbers and get a bottom-line calculation.
Find conversion software that fits what you want to do and use it to convert into JavaScript.
WordPress Don’t overlook WordPress. Plugins extend the functionality of WordPress, and there are thousands of plugins available. It’s another way to do embedded programming in a webpage.
What exactly is JavaScript? Well, it looks like this:
<script type="text/javascript"> function vidplay() { var video = document.getElementById("Video1"); var button = document.getElementById("play"); if (video.paused) { video.play(); button.textContent = "||"; } else { video.pause(); button.textContent = ">"; } } function restart() { var video = document.getElementById("Video1"); video.currentTime = 0; } function skip(value) { var video = document.getElementById("Video1"); video.currentTime += value; } </script>
Let’s assume that the JavaScript above is a JavaScript that you want to embed in one of your webpages. How do you do it? There are three ways you can do it.
First, you can put the JavaScript in a separate file (plain text file), and reference that file in your webpage <head>.
Second, you can put the entire JavaScript in the head of your webpage and reference it in the body.
Third, you can actually put the JavaScript into the body of your webpage.
Let’s see how this works. If the JavaScript is huge (many pages of script), you will want to put it in a separate file to get it out of the way (a JavaScript file is a text file that has the file extension .js). Then use HTML in your webpage to link in the JavaScript.
If the JavaScript is fairly short, you might want to include it in the head of your webpage where it stays out of the way. Again, you call up such a JavaScript in the body of your webpage.
Finally, if the JavaScript is very short, you can include it right in the body of your webpage. There are no hard fast rules on what is huge, what is short, and what is very short, so you are free to do whatever you please.
The normal way to embed JavaScript into a webpage is with the HTML5 markup, which has six attributes:
<script> </script>
HTML5 includes a lot of functionality that enables a certain amount of programming. For instance, you don’t need anything except HTML to create a hyperlink. You simply use the hyperlink markup in HTML5. Creating a hyperlink couldn’t be easier. But HTML5 has its limits. And its limits are essentially that it’s a digital publishing markup language; it’s innate programming capability focuses on doing publishing kinds of things.
On the other hand, JavaScript is no such limitations. If you can do it, you can probably do with JavaScript, unless you want to send a woman to Mars or predict the weather in Manila a month from now.
Again, as I’ve said in other chapters, don’t try and load your entire webbook up with JavaScripts just to be cool. Try a few here and there. Once you’ve had some success at the spiffy things you can do with JavaScript, you will be able to embed more later. Remember a webbook is always a digital work in progress every day.