GEEK I am having trouble accessing the value attribute of an option tag when using Netscape Navigator. Here is some sample code:
<script LANGUAGE="javascript">
<!
function isReady(form)
{
if (form.selection.value == "")
{
alert("please make a selection.");
form.selection.focus();
return false;
}
}
//>
</script>
<FORM Name="form1" onsubmit="return isReady(this)">
<SELECT NAME="selection">
<OPTION VALUE="" SELECTED>
<OPTION VALUE="1">option1
<OPTION VALUE="2">option2
<OPTION VALUE="3">option3
<OPTION VALUE="4">option4
<OPTION VALUE="5">option5
</SELECT>
The only thing returned for selection.value is null (no matter which option is selected). This code works fine for Microsoft® Internet Explorer, but not Netscape Navigator; can you tell
me why?
selection.value
a shortcut method for getting to the currently selected option value of the <select> element, is only supported in Internet Explorer 4.0 at the moment. The verbose way of getting to this value in the other browser is:
selection.options(selection.selectedIndex).value
GEEK I am new to writing programs in Visual Basic®. I can't seem to figure out how to get music to play automatically on load in my program. I'd like my program to play a .wav file
on initial load, without the user clicking any buttons. Also, is
it possible to make a screensaver that plays a .wav file in the background?
GEEK I have an ASP page that contains a form to search product descriptions (see Figure 1). I would like to have the form submitted after the user types in the text and presses Enter. I have another form in which the only elements are a text box and a submit button; pressing return in the textbox does submit that form. Is there a trick to submit the form when it has multiple elements?
GEEK In the purest sense, a form with only a single input element will automatically perform the submit method when the Enter key is pressed; a form with more than a single input element may not. Internet Explorer 4.0 actually does a pretty good job with your form code as you list it, and no matter what element has the focus, when the Enter key is pressed, the submit action will be called. Internet Explorer 3.0 and Navigator 4 will only submit the form if the element whose type is set to "text" has the focus, not the radio buttons or checkboxes.
To control what happens when the Enter key is pressed when any form element has the focus, you should define an onkeyup event handler for your form, something like this:
<form onkeyup="if (event.keyCode == 13) {ProcessForm()}" ...>
the function ProcessForm will perhaps validate the values on the form, then call the form's submit method.
GEEK Using JScript®, is it possible to highlight only a portion of text in a text input element?
GEEK Yes, you can utilize the TextRange object to do this. Figure 2 shows a simple example.
GEEK How can I create a custom postcard on the Web? I would like a user to select an image, type in a personalized message, and specify the email address of the recipient. The Web application would then take the image and merge it with the text; the file that's mailed to the recipient is an image file of the original image with the text written in white space on the side, like the real thing. I've seen this done on some sites, but I can't figure out how it's done.
GEEK What you are describing is the creation of custom graphics based on user input. Assuming you are familiar with Windows-based programming, you could do this by developing an application that runs on the server, and automatically does the following when an "order" comes through:
GEEK I am working on a project in Visual Basic 5.0 that requires the WebBrowser control. I was able to create a program that loads and navigates a URL.
I would like to have the raw HTML source of the page loaded in the WebBrowser control. How do I do that in Visual Basic 5.0? Is it possible to collect information about all the external links in that page, local and external (images, external
pages), and so on. How can I use POST (submit data) with
this control?
GEEK Visual Basic gives you pretty robust access to the properties, methods, and events of the WebBrowser object. In addition to all of the various things that VBScript on a Web page can access as the "creator" of the WebBrowser control, there are a number of additional capabilities that are exposed for this component. Here is a good place to see what some of these are:
http://msdn.microsoft.com/developer/psdk/ inetsdk/help/itt/ieprog/wb/objects/webbrowser.htm
For what you want access to, you can simply deal with the normal properties that are exposed via the DOM (Document Object Model) of Internet Explorer.
I'm not sure precisely what your application is, or why you want to display the "raw HTML source of the page," but I would recommend that you not display this within the WebBrowser object; this would overcomplicate things. I would recommend instead simply displaying the text in a standard multiline edit control, or if you want to avoid the ~32KB standard edit control text limit, you could use the RichEdit control instead.
Say you've created a WebBrowser object called WB on your Visual Basic form, and you've created a multiline edit control called TextView on your form. To show the raw HTML of the page, you could use this code
TextView.text = WB.document.body.innerHTML
to transfer the HTML for rendering the page into the TextView control.
WB.document.body.innerText = WB.document.body.innerHTML
And since the innerText property will filter all incoming text so that it displays as it is given, instead of trying to render things as HTML, this will display the source of the page.
For Each webImage in WB.document.images
TextView.text = TextView.text & vbCRLF & webImage.src
Next
and use similar code for anchors.
http://server/page.asp?item1=value&item2=value
which will work fine.
GEEK Nice tip about the page-break-before style in your July 1998 column. Unfortunately, the way you presented the example, it doesn't work. This snippet (tested with Internet Explorer 4.01 Visual Studio® build) was broken:
This is a test of the emergency broadcast system
<HTML>
<HEAD>
<STYLE>
.pagebreak {page-break-before:always}
</STYLE>
</HEAD>
This is on page 2
<br class="pagebreak">
It appears that Internet Explorer cannot render that style sheet unless you have a fully enclosed tag that includes some text between it. This works
</HTML>
and most other text formatting tags do too. But any single item tags or any tags that have nothing in between them will fail:
<h1 class="pagebreak">Page 2</h1>
I don't see a way to easily insert a page break. Do you?
<br class="pagebreak">
<p class="pagebreak"></p>
<h1 class="pagebreak"></h1>
GEEK Dang, that's what I get for extrapolating information and thinking it is straightforward enough not to test it first.
When I use forced page breaks (which I don't do very often), they're usually part of a header tag, or occasionally they're in a paragraph tag. But you are right, the implementation requires an actual display block item in order to generate a page break. And unfortunately even an <hr> doesn't qualify as a display block, much less a <br>.
So the best way to use a forced page break is to associate it directly with a element that contains text. If you want a standalone element to insert that includes (virtually) no display qualities of its own, the simplest would probably be:
<div class="pagebreak"> </div>
Probably the best way to use this is in conjunction with your actual page information, in such a way that there is a logical reason for producing a page break. A header element (such as <h1>) is an excellent candidate since it already is an indication that some new block of information is starting.