"A Tutorial by Victoria Leonard"
|
|
The Misunderstood Textarea Object <textarea NAME="getThis" COLS="60" Rows="7">Default Text</textarea> Again, the COLS and ROWS refer to the number of characters the field can accommodate using the fixed-font chosen in the browser preferences. Now for the things to watch out for.
The following is a version of the code that I use to check my JavaScript as I write it. The code itself goes in the textarea and any variables whose values I want to check go in the text fields in the lower left. evaljs.html Evaluating JavaScript in the Browser <html> <head> <title>Evaluating JavaScript</title> <script language="JavaScript" type="text/javascript"> function display() { document.mainForm.elements[3].value = eval(document.mainForm.elements[0].value) for ( var n = 5 ; n < 8 ; n = n + 2 ) document.mainForm.elements[n].value = eval(document.mainForm.elements[n - 1].value) } </script> </head> <body onLoad="document.forms[0].elements[0].focus()"> <form name="mainForm"> <!--Prompt for Code--> Type Some JavaScript Code Here: <textarea NAME="getThis" COLS="60" Rows="7">Default Text</textarea> <!--Buttons--> <input type="button" value="EVALUATE" onclick="display()"> <input type="reset" value="CLEAR"> <!--Display Evaluation Results--> <input type="text" name="putHere" size="60" value=""> Variable: <input type="text" name="varA" size="31" value=""> Has Value: <input type="text" name="valA" size="31" value=""> Variable: <input type="text" name="varB" size="31" value=""> Has Value: <input type="text" name="valB" size="31" value=""> </form> </body> </html> In this code, function display() runs the eval() method on the contents of the form's first element, which is a textarea. If you type a function into the textarea, you will see what the function returns in the text field under the buttons. The buttons are the second and third elements, so the text field is the fourth. The script then executes a loop. Starting with the sixth element, it puts into every other field the value of the field before. For instance, let's say that you have a variable "runningTotal" in your code. You do a number of things to this variable in one or more functions which you type into the textarea. If you put the name "runningTotal" into one of the text fields in the lower left, the corresponding field on the lower right will tell you what the value of this variable is after all the code has been run. I have tried to eliminate extraneous HTML formatting from the code samples, but you will see it if you view the source of the running code. None of this affects the function of the page. It just makes the function easier to follow in the browser, if not in the code. In the next section, we look at some text validation techniques. Pages in the Tutorial
|