Highjacking The Form Submit
Now that control has been wrested from the form and turned over to the processdata function, the remaining functionality for the routine can be executed in the function:
The simple function first calls another function named mainroutine which contains the code I wanted executed, and then handles the document submission with the document.mainscreen.submit method - mainscreen being the name of the form.
Stopping The Page Refresh
The next situation I encountered was that the web browser assumed that since I was submitting form data I would want to provide a destination page in my PHP code and redirect to that page - or at the very least refresh my current page. What I wanted to do was return to my original page without forcing a page refresh. To accomplish this I had to enter a new line in my PHP script:
I placed this line at the very end of the script. It sends the 204 response code back to the client which indicates that no page is available to return.
Reloading The Animated Gifs
At this point I actually thought I was done, but then I noticed that gif animations on my page had frozen. The stopping of the animations was apparently an artifact of the form submission. The trick to restarting the animations was to use the innerHTML method to reload them into the current document. First, within the body of the page, I enclosed the graphics with span tags and gave them the ID of gif1 and gif2 so that I could refer to them later:
Then I added code to my processedata function described above to refresh the areas defined within the span tags, so that the full function now looked like this:
Note that I had to escape out the quotation marks using the \. The actual reading of this code seems silly, because I'm just reloading the values into gif1.innerHTML and gif2.innerHTML that were already there. It does, however, setup the possibility of expanding the technique to replace animated gifs on the fly without refreshing the page.
In closing, I'd point out that none of these techniques were difficult. The onkeypress event handler and the innerHTML method are both very well documented. Returning the 204 code in the HTTP header was a little trickier but still easy once I figured it out. The trick was putting all the techniques together to accomplish something that seemed very straightforward to me, but nonetheless violated several normal HTML behaviors.
See more from Web Design
Other Pages You Might Enjoy...
The Meissen Porcelain Manufactory
For more than 300 years the Meissen Porcelain Manufactory has been a central figure in European porcelain. It was at Meissen that the first true hard-paste porcelain was manufactured outside of China, and the story of that accomplishment has the high drama of fiction - all the more intriguing because it is true.
Pirated Glassware that Collectors Want to Own
The 1996 discovery of what is believed to be the wreckage of Blackbeardís ship Queen Anneís Revenge, is providing historians and collectors new information about the fragile and transparent objects that came onto the North American Continent before arrival of the first piece of cut glass.
Collecting Antique Furniture
Of all the collectible antiques, the broad category of furniture is perhaps the most widely held and most satisfying. Frequently handed down through generations, the various chairs, tables, cabinets and other pieces are often in use, adding character and constancy to our daily lives. This guide includes an overview of the significant styles and historical periods, and other important information for collectors.
Collecting Antique Clocks and Watches
Information for collectors of antique clocks and watches. Includes a history of clock and watchmaking, an overview of styles, and important terminology.
Collecting Antique Jewelry
Embodying the wealth and treasure of bygone days, the antique jewelry pieces available today include some of the world's most valuable artifacts. Includes a history of jewelry making, an overview of the major historical periods, and a glossary of antique jewelry terminology.
Home of the Do It Yourself Chatterbot Project. Has a ready to go chatterbot shell and full instructions on how to program it.
Tips for Improving Website Navigation
A business often has more than one target audience it wants to reach with its website. Different customers mean different sales appeals and a homepage needs to be able to direct visitor traffic to go to the right places to get information or make a sale.
Choosing the Right Color for Your Web Site
When people build a web site for their business (or hire a web design company to make it for them), not much thought is put into deciding what color their web site will be as most would rather focus on more important tasks like creating content, web site optimization and promotion. Most simply choose the most web-friendly colors, others use their companyís logo as base while some decide to just use their favorite color.
Beginning at the Beginning - File Systems and Plain Text Files
HTML For the Absolute Beginner
The intent of this tutorial is to provide a basic introduction to making web pages for the person who has never studied HTML before. Once one has worked through this material they should be able to create a bare bones HTML file and be ready to move on to learning to build web pages.