Frames and Forms and Elements, Oh My!
One of the most common uses of scripting is to respond to events from a form, such as typing text into a text box or checking data when the Submit button is pressed. There are two ways to reference form elements. First, you can reference them through the Object Model. document.form(0).elements(1).value refers to the Value property of the second element in the first form on the page. You can determine the number of forms in the page using document.forms.count, and can determine the number of elements in the first form using document.forms(0).elements.count.
This is an awkward way of referring to elements. Instead, if you include a Name attribute in the form and element's HTML tags, you can refer to it by that.
<form action="http://www.lycos.com/cgi-bin/pursuit" method=GET
And here is the result. A form which searches Lycos, but won't submit unless you've chosen a search type, and typed in a keyword.
Note: This is a variation of the search form that Lycos makes available for use on other people's pages.
Notice that you can return false in an event handler, and it will cancel the event. In this case, returning false makes it so that the form does not submit.
window.frames is like document.forms, in that it can contain multiple instances that can be referred to by name or index, and has a count property. The difference is that while forms contain elements, frames contain a document object.
Frames are much like windows. The contain a document, and can contain other frames. In fact, in almost all ways, you can treat a frame as if it was a window.
You can refer from one frame to another by using the window.parent object. It points at the window above it.
Frames are supported in NN2+ and IE3+, and are part of the HTML4 specification. For scripting, though, floating frames are even more useful than regular frames. The IFRAME tag allows you to make a frame which sits in the middle of a page, like an image. It is supported by IE3+, and is not part of HTML4. They are referred to in the same way as regular frames.
Below is an example of a scripted floating frame. (Can only be viewed in IE3+)
" SPre3 = "" SPre4 = "" SPre5 = "" EPre = "<" & Chr(47) & "PRE><" & Chr(47) & "BODY>" Sub AnimHelloFrame1 Window.fraHello.Document.Write SPre1 & "H " & EPre Window.fraHello.Document.Close SetTimeOut "AnimHelloFrame2 True", 250, "VBScript" End Sub Sub AnimHelloFrame2(forw) Window.fraHello.Document.Write SPre2 & "He " & EPre Window.fraHello.Document.Close If forw Then SetTimeOut "AnimHelloFrame3 True", 250, "VBScript" Else SetTimeOut "AnimHelloFrame1", 250, "VBScript" End If End Sub Sub AnimHelloFrame3(forw) Window.fraHello.Document.Write SPre3 & "Hel " & EPre Window.fraHello.Document.Close If forw Then SetTimeOut "AnimHelloFrame4 True", 250, "VBScript" Else SetTimeOut "AnimHelloFrame2 False", 250, "VBScript" End If End Sub Sub AnimHelloFrame4(forw) Window.fraHello.Document.Write SPre4 & "Hell " & EPre Window.fraHello.Document.Close If forw Then SetTimeOut "AnimHelloFrame5", 250, "VBScript" Else SetTimeOut "AnimHelloFrame3 False", 250, "VBScript" End If End Sub Sub AnimHelloFrame5 Window.fraHello.Document.Write SPre5 & "Hello" & EPre Window.fraHello.Document.Close SetTimeOut "AnimHelloFrame4 False", 250, "VBScript" End Sub Sub Window_OnLoad() AnimHelloFrame1 End Sub -->