Create a File-based Blog using Jaxer [con't]
window.onload event handler, which sets the handler for the
form.onsubmit event. Notice that it's an ideal place to use anonymous functions, because once a listener is in place, we do not need to reference it again:
onsubmit handler verifies that the
txaPostText field contains a value and then calls the server-side
save() function. Upon a successful save, the new post is appended to the bottom of the list, and the textarea is cleared. In the event of an error, an alert box informs the user. Finally, the event is cancelled using Prototype's
event.stop() function, and the focus is reset on the
txaPostText field. We could have dispensed with the form and assigned our function to the button's
The event listener pattern that we saw above can just as easily be applied to the server-side
init() function. Although it is also appended to the
window object, it needs to be separate from the other, client-side handlers. Don't forget to remove the
onserverload="init()" from the
<BODY> tag. Here's what it the
init() function should look like now:
runatattributes to 'both', as the
save()function references both of them.
Jaxer Server on the
Servers tab, and clicking the
Open Log button.
Here is the blog.html page with today's changes and additions.
We'll be looking more at server errors next time, as we explore script debugging using Aptana. Later, we'll extend the project to add a page where posts are re-ordered and/or renamed, and move to using a database instead of text files.
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. Rob's latest, entitled KNIGHTFALL, was a collaboration between himself, the former Ivory Knight vocalist, and legendary guitarist/producer, Jeff Waters of Annihilator fame. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: August 7, 2009