Wednesday, January 10, 2007

AJAX and The innerHTML Problem

Here at Road to the Middle Class we are nothing if not modern.  That means that the site ought to be LAMP compliant, using Linux, Apache, MySql, and PHP, and so it does.  But now, according to The Economist and Eric Schmidt, CEO of Google, it appears that a truly modern site should use AJAX as well.  AJAX (Asynchronous JavaScript and Xml) is the technology that Google uses on GMail.

Well, how hard could it be?

The standard demonstration of AJAX on W3Schools.com shows how to use an AJAX setup to update text hints on the fly.  You press a key to enter a character in a text box and every time you release the key your page requests a new text hint from the server with an HttpRequest.

When the response comes back from the server you update the text hint element like this:

document.getElementById("txtHint").innerHTML =xmlHttp.responseText

And everyone is happy.

But there’s a problem.  The best use of AJAX here at Road to the Middle Class is to fold/unfold blog entries.  We conserve real estate by showing only the first 50 words of a blog and allow you to click a link to get the whole article.  But that means that the content coming back from the server is going to include HTML markup.  What happens if the responseText isn’t just simple text but includes embedded HTML? 

Good question.  It turns out, using the W3Schools example, that embedded HTML works on Firefox but not on our friends at Internet Explorer: IE6 and IE7.  The IE boys take one look at the embedded HTML and decide that it’s not a job for innerHTML.  They return an "unknown runtime error".

Here’s how you update your page with AJAX when the responseText is complex and includes embedded HTML as it is here at Road to the Middle Class.  I call it the Double Span Solution.

First of all, you surround your text with two <span> elements, like this:

<p><span id=blog101><span id=blog101s>
<p>Text including a <a href="">link</a> and stuff.</p>
</span></span>
</p>

The idea is that when you want to replace the text in the middle of the two <span> elements you replace the entire inner <span> element.  You delete the old <span> and add a new <span> with the responseText and all of its HTML markup.

First of all you set up the new <span> element, preserving the element id from the old <span> element and adding in the responseText from the server.

var elem = document.getElementById("blog101s")
var newSpan = document.createElement(’span’)
newSpan.id = elem.id
newSpan.innerHTML = xmlHttp.responseText

Now remove the "blog101s" element and anything else floating around.

for (var i = 0; i < document.getElementById("blog101").childNodes.length; i++) {
   var n = document.getElementById("blog101").childNodes[i]
   n.parentNode.removeChild(n)
}

OK.  Now append the new <span> element right under "blog101".

document.getElementById(gBlogid).appendChild(newSpan)

And that should do it.

Tuesday, January 9, 2007

Dont Forget Most Old Media is Union Shop

Dear old TIME magazine is slimming down, according to The New York Times.  Writes reporter David Carr

Time Inc. management, with the help of air cover from the consultants from McKinsey, is trying to cut costs to reflect brutal realities in the mass magazine business. At the end of the month, there will be significant layoffs at the magazine division, and it will not end with Time’s 280 editorial employees.

You can imagine that American Thinker editor Thomas Lifson isn’t exactly in tears. 

Does the world need TIME? I can’t think of a reason why. I have to wonder if McKinsey [TIME’s expensive consultant] didn’t present shutting down the magazine as one of the main options for management to consider.

The thing to remember is that Old Media is organized in a hauntingly similar way to Big Auto.  The help is all unionized.  You may not realize this, because when journalists write about labor relations they do not add a little tag "full disclosure: reporter is a union member," which they would do if, say, writing about their alma mater.

Yes.  Any time you read an article by a big-foot journalist you are probably reading words written by a member of the Newspaper Guild.  The guild is now part of the Communications Workers of America.  That means, of course, that they are probably being paid way above what the market would bear.

And that makes the situation of the MSM even more tricky.  Because they are stuck with a cost structure that is way out of line with reality.

Back in the old days the only way you could get your name in print was on somebody else’s dead tree.  And the barriers to entry in the dead-tree business meant that the union journalists could charge monopoly rates for their services.

Those days are over and the dead-tree titles are desperately trying to slim down.

Here for instance, is a report in Editor and Publisher about print unions complaining about the slimming down of The Wall Street Journal.

The union [IAPE] representing staffers at the Journal took out an ad today in a rival, The New York Times, calling into question Dow Jones’ commitment to quality journalism.

Well, surely you wouldn’t expect them to take out an ad in the Journal?  And you surely don’t expect them to take a "proposed increase -- 400% according to the IAPE -- of health care costs" without complaint?

Do You Believe in Education Myths?

With something as politicized as education you always wonder about what you read in the paper or watch on the news.  After all, the media is not called the media for nothing.  It is a medium, a channel of communication.  There is a lot of money in education.  Money and power.  With all that money and power, how much of what we know about education is true? 

Jay Greene is an expert on education policy and he’s written about his findings in Education Myths.  The full title is Education Myths: What Special Interest Groups Want You to Believe About Our Schools--And Why It Isn’t So.  So you can see where he is coming from.  Greene writes: 

Over the past 30 years, many of our education policies have been based on beliefs that clear-eyed research has recently shown to be false. Virtually every area of school functioning has been distorted by entrenched myths.

OK.  Let’s have a test of education knowledge.  Which of the following generally accepted ideas are true?

  • Schools are underfunded.
  • Teachers are underpaid.
  • Schools can’t be expected to overcome the effect of social problems.
  • Smaller class sizes produce better results.
  • More credentials means better teachers.
  • Penniless public schools can’t compete against rich private schools.
  • School choice and school vouchers don’t work.

The answer, of course, is none of the above.  All of the above ideas are education myths.  Want to know the correct answers?

  • Schools have received a vast increase in funding in the last 30 years. 
  • Teachers are paid at about the same hourly rate as engineers, architects and other professionals.  They are less well educated and have better tenure than the other professionals.
  • Schools can make a dent in social problems; in fact that is what the father of the common school, Horace Mann, promised 150 years ago. 
  • Smaller class sizes don’t seem to make much of a difference. 
  • Credentials don’t seem to make a difference. 
  • Public schools have much more money per student than private schools, and that is still true if ignore the money spent on bureaucracy and special needs.
  • And, of course, school choice and school vouchers work, not just for the kids at charter schools and private schools but at the public schools forced to compete with them.

It’s a grim prospect.  How could we all be so wrong?  But Greene isn’t discouraged.  He takes the long view.

Disentangling popular misconceptions from our education system--and establishing fresh policies based on facts that are supported by hard evidence--will be the work of at least a generation.

Go ahead, read the whole thing.

Monday, January 8, 2007

Let's Not Blame Conservatives On Education

Oprah is getting a bit of flak because she is funding a school for girls in South Africa, according to Clarence Page.

"I became so frustrated with visiting inner-city schools (in America) that I just stopped going. The sense that you need to learn just isn’t there," she said. "If you ask the kids what they want or need, they will say an iPod or some sneakers. In South Africa, they don’t ask for money or toys. They ask for uniforms so they can go to school."

And just because she amazed and delighted conservative commentators,  "that doesn’t mean she’s wrong."

In fact, Page agrees with Oprah.

She’s not blaming the victims. Our kids don’t know anything except that which they are taught by parents, peers, teachers and other role models.

If kids just want iPods, then it’s what just what they are taught.  "We" are all to blame.

Excause me, Mr Page.  "We" are not to blame.  You are to blame.  You liberals.

For over 150 years we have had a one-size-fits-all government school system run most of the time by liberals.  It bores most kids out of their minds, and it does nothing to channel the group activities of teenage boys into beneficial channels.  This system was set up by liberals and it is presently run by liberals.

And it is liberals that are standing in the school house doors stopping education reform in its tracks.

What shocked and amazed conservative commentators about Oprah was that any liberal would break ranks and criticize the current system.  Oprah is saying that she’d be wasting her money by building a school in this country.

And hey, it’s her money.

Besides, if we really want our kids to appreciate education, we should follow Oprah’s example: Fix up the old, crumbling structures into which we herd too many of our students here at home. If we want our kids to appreciate education, we have to show some respect for it, too.

Oh really.  What planet are you living on.  Most of the schools in this country are palatial.  And they still don’t educate.

Let’s try something new.  Let’s give parents the right to send their children to the schools of their choice.  What a concept!

Stand Firm on Social Security!

Is the new Democratic Congress a big deal?  Is it going to change the political weather, long term?  Bill Steigerwald asked Fox News reporter Major Garrett about that.

There is bad news, very bad news.  Says Garrett: 

Also, I think there is movement afoot to deal with Social Security -- not on the president's terms, not on post-2004 election terms of personal accounts, but entirely on Democrat terms, meaning no personal accounts or maybe something that bears some ghostly resemblance to a personal account, but higher taxes or some rejiggering of benefits along a much more traditional line of quote-unquote "fixing" Social Security.

I fail to see the point of Republicans voting for a fix (i.e. tax increase) on Social Security without a getting a very big camel's nose of personal accounts under the tent.

What's in it for Republicans, or for the nation for that matter, if we just crank up a tax increase?  It just puts off the day when we really have to fix Social Security.

The fact is that the current pay-as-you-go model is unsustainable.  Always was, always will be.  One day we are going to have to throw it away and go to the only sustainable model, a savings model.  The savings model is simple.  When you have saved enough money, then you can retire. Personal accounts gets us on that road.

Of course, we will always help people to get too old to work and don't have enough saving through no fault of their own.

A tax increase, any tax increase, just gives the federal government more money to spend.  That means more money to buy votes.  It puts off the day when real spending cuts must start.  Put another way, it puts off the day when real reform of the corrupt welfare state begins.  And that just plays the Democrats' game.

And, of course, any increase in marginal tax rates--such as on the richest Americans--just slows down the economy. 

Stand firm, Mr. President!  Stand firm you Republican Senators!  Make the Democrats pay for their Social Security fix.

Saturday, January 6, 2007

"Broken Windows" Eat My Dust

It had to happen. Sooner or later some criminal justice entrepreneur would consign the "broken windows" theory of policing into the dustbin of history.

Broken Windows, remember, is the brilliant concept developed by James Q. Wilson and George L. Kelling and famously implemented in New York City by Joseph Bratton.  The idea was to arrest vandals and turnstile jumpers because it usually turned out that they had outstanding warrants, sometimes for serious crimes like rape and murder.

But that's old hat now.  The British cops, as reported by Simon Heffer, have now come up with "disabled parking space" policing.  Heffer's source, a "chief constable" or in US terms, police chief, 

told his officers to question the drivers of every car improperly parked in a supermarket disabled parking space, for this reeled in huge quantities of villains. The vehicles concerned were almost always illegal in some way, and the occupants often wanted on bail warrants, or for more serious crimes.

Talk about a natural.  Now the cops can just sit in the Starbucks built into most every supermarket, drinking coffee and eating a don... --er make that a freshly baked organic muffin--and just check out the license plate of every car that parks in the nearby handicapped parking space.

Friday, January 5, 2007

Tasteless Atheists

There have been a lot of books written by atheists about the folly of religion recently, and they tend to take a rather high line with believers. 

Apart from the usual bromides about religion causing wars, and religious people hopelessly missing the point about evolution, they proudly parade their "rational ethics" as a substitute for belief.

As Sam Schulman writes:

They write as if great minds had never before wrestled with the big questions of creation, moral law and the contending versions of revealed truth. They argue as if these questions are easily answered by their own blunt materialism. Most of all, they assume that no intelligent, reflective person could ever defend religion rather than dismiss it.



Richard Dawkins in The God Delusion complains about people accusing him of being very "nineteenth century."

Actually, it is probably more accurate to call him "eighteenth century."  He seems to think that we are still arguing about the proofs of God's existence.  But I thought that Kant had put that one away two hundred years ago and more when he showed that you couldn't prove or disprove God's existence.

But Kant did something more.  He claimed that we couldn't know reality, things-in-themselves, but only appearances.  He must have been onto something because a century later a young German kid completely upset the assumptions about space and time by saying that space and time were relative, not absolute as Newton had assumed.

Atheists like Dawkins and Sam Harris of The End of Faith don't engage with Kant, and that's a shame.  They delight their followers by beating up on the small fry like fundamentalists and the religious right instead of dealing with the big beast.  

Kant is generally thought to be the most important philosopher since Aristotle, so what he wrote about God would have to be important, you would think.

By the way, Sam Harris writes a lot about in The End of Faith about "rational ethics," but when it comes to the point he just presents his idea of the end of ethics as increasing happiness and decreasing suffering as given.  How rational is that?