Search Box Script Error in Ads Theme Template

Posted by Prem Godara | 11/10/2008 09:36:00 PM | , | 0 comments »

Recently, i downloaded Ads Theme Template for my website from eBlog Templates. But after uploading it into Blogger, I noticed a JavaScript error. I traced the error in the Search Box of the Template.

The error occured because the 'apostrophe' was not getting escaped in the <input> tag of the HTML. This happened because the interpreter reads the first quote it encounters as the beginning of the string, and reads the very next quote it encounters as the end of the string, we need a way to signify that a quote is part of a string and not the end of it.

There are two ways to accomplish this goal: nesting opposite quotes and using a special character called the escape character.

I solved this error by nesting opposite quotes.

Below is the code before fix:

<input class='s' id='s' name='q' onblur='if (this.value == \'\') {this.value = \'To search, type and hit enter\';}' onfocus='if (this.value == \'To search, type and hit enter\') {this.value = \'\';}' type='text' value='To search, type and hit enter'/>
After the fix, the code will look like this:
<input class='s' id='s' name='q' onblur='if (this.value == "") {this.value = "To search, type and hit enter";}' onfocus='if (this.value == "To search, type and hit enter") {this.value = "";}' type='text' value='To search, type and hit enter'/>
Save the template and reload the page, script error won't occur again.



0 comments

Post a Comment


Your Ad Here