http://qs1969.pair.com?node_id=578202


in reply to Adding fields to a form using Catalyst/TT

Javascript is a very nice language which does not deserve its even worse reputation than our favorite language. I was in your position about 6 months ago, so I read a book on the language (Java Script the Complete Reference 2ed., I heard a new O'Reilly title was coming soon, but it wasn't soon enough) and discovered that javascript is very flexible in surprisingly perlish ways (although the syntax looks different than ours at first glance).

A previous poster mentioned libraries, which are great. But, understanding comes to me from rolling a few things myself first. Otherwise, I can't conceive of what the library is up to.

Here is a little sample pulled from recent code (Bigtop's tentmaker editor to be specific). I've pruned it a little bit to make it clearer and more general.

function add_to_div( div_to_change, new_div_text ) { var div_area = document.getElementById( div_to_change ); var new_node = document.createElement( 'div' ); new_node.innerHTML = new_div_text; div_area.appendChild( new_node ); }
Now this is not fancy. Library code would be nicer in a number of ways (notably in cross browser support). But this shows how easy it is to augment an existing document object model (DOM).

Other than javascript, you can only make round trips to the server, which is <pun_warning /> anything but refreshing.

Phil