How to Write a Script Code

You can write a script code by first determining which kind you want to run. The two more common types of script are called "JavaScript" and "Visual Basic," or "VB" script. Learning these light programming languages is almost like learning a foreign language. Each has rules to follow, and with a little practice, you'll be able to write a script code skillfully.

Things You'll Need

  • PC or laptop
  • Basic HTML
Show More

Instructions

  1. Write Script Code

    • 1

      Format your web page. You have to think about how you want to pattern your web page before you write a script code. Have your web page file open before you write a script code, too. Do this by simply opening a file using Notepad or your code editor. If you do not have an editor, the Notepad application on your computer will work just as well. You just need to be careful how you write your script because there is no software to catch any potential mistakes. Next, place your script between either the head or body tags. Tags will have angle brackets around them and will look like this: "<head>, </head>" or "<body>,</body>."

    • 2

      Tell your computer which type of script you want. At the beginning of writing a script, you have to tell a computer which language it will be reading. Type the word "type" and then put an equals sign directly to the right. Write "text/javascript" or "text/vbscript" after that. Be sure to place angle brackets and quotes around your words, as well. Your script should look like this: "<script type="text/javascript"></script>." To change your script, simply replace javascript with "vbscript."

    • 3

      Use "document.write" with parenthesis and place the words you want to read after. Place the appropriate command language between the open and closed script tags. Both JavaScript and VBScript pattern the language the same way. The words "document.write" simply means that a computer is going to write a document to read whatever words you tell it to. Your first lines will appear: "<script type="text/javascript">document.write("This is the text that will appear when a Web page opens.")</script>." It is a good idea to place the document.write line on the next row for consistency. Javascript also requires a semicolon at the end of a script line, too. VBScript does not have this requirement.

    • 4

      Type "var" for a variable if you want to run a dateline script. Both JavaScript and VBScript let you add a little "flare" to your script writing. Write a script code to have a date and time show up at the top of your page. You have to give your variable a name and write parenthesis at the end of the name like this: "Date ()." There isn't any big complex reason for this, just a style-standard mainly. If you want to use JavaScript type: var d=new Date()." Remember to place a semicolon after the end parenthesis. Again, this is just a style-standard all developers agree on to make writing a script code a little easier for everyone globally. Further, don't forget to use your document.write language and then put a "d" inside a set of parenthesis like this: "(d)." You could really name it with any letter, but just remember to keep the name consistent. It will be a lot easier to remember if your script code becomes very long. Write a script code for this as follows: "document.write(d);."

Tips & Warnings

  • Place your script code between the "<head>" tags to enable your code to run when a page opens.

  • Make sure to use both open and closed tags when you write a script code. You can receive numerous "error" messages if you do not. It is often difficult to decipher a mistake in script code, especially if the script runs for multiple pages.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured