Javascript Tips and Tricks

Should You Get Java and JavaScript Off Your Computer? by Kelly Lynn

  Computer security columns evangelize how important it is for people to disable JavaScript on their computers. They tell you that your computer’s security is seriously compromised if you keep JavaScript on your computer. Is this true? JavaScript makes much of the modern Web experience possible. Is the security threat serious enough that you should hobble your Internet experience to this degree? What exactly does JavaScript do? JavaScript is the programming language that makes webpages come alive. It is used to program nearly every web browser. Many people confuse JavaScript with Java – a plug-in that you need to install separately. Java, the plug-in, is created and maintained by a separate company called Oracle that often seems to not care about good security practices. Major industry experts recommend that everyone … Continue reading

How to Validate a Web Form with JavaScript by Kelly Lynn

If you’re building a website, at some point, you’ll probably need a form so users can submit data. Forms are easy to build in HTML and you can add some simple JavaScript to your page to make sure that users submit valid data in the form fields. Let’s take a look at how to use JavaScript to validate some commonly used form fields. The HTML Form First we’ll create a basic form in HTML. Users will enter a name, email address, and age on the form: The HTML code for the form is very simple: <form id=”SampleForm” onsubmit=”validateForm();”> Name: <input type=”text” id=”SubscriberName”><br> Email: <input type=”text” id=”Email”><br> Age: <input type=”text” id=”Age”><br> <input type=”submit” value=”Submit”> </form> The JavaScript Function Now we need to add a JavaScript function to make sure that the … Continue reading

Cross-Origin Resource Sharing by Michel Plungjan

Background For a long time developers pulled their hair out when attempting to get Firefox (Fx) to allow a script from one domain to read a file from another domain via XMLHttpRequest. The two most common solutions I saw and used were: inserting a script which returns JSON (JSONP) using a proxy on one domain to connect to another domain which fetches JSON. IE is less choosey, and on an intranet, one can simply add the foreign site as 'trusted' and simply go get the data. Woot! In June 2009, with the release of Fx 3.5, a small change suddenly made a lot of hacks redundant: have the target server add a simple header to their response, and Fx will happily accept the data. had implemented the client side … Continue reading