Sunday, March 22, 2009

IE8 JavaScript Debugger statement not working

Well I just downloaded Internet Explorer 8, after playing with it for a while, I started programming using. I have Visual Studio 2005 installed on my box, and suddenly I notice that IE8 is not responding to my “Debugger” statements in the JavaScript. After numerous Google queries i decided to take matters into my own hands. I started playing with built in debugger’s option, within few seconds what I saw “Script” tab inside I saw “Start Debugging” button. So all I had to do was to click on Start Debugger and suddenly it started hitting all the “debugger” statements.

image

Tuesday, March 17, 2009

On Postback or Submit button new window opens

Several days ago, I came across issue, when I click on button inside a dialogbox’s it opens up a new window. So I asked one of the co-worker see if he has seen this behavior, and he goes like just add below code inside head tag. 
<base target=_self>

Note: this will not work with IE5

Sunday, March 08, 2009

JavaScript When you using pareseInt() Why you should always put radix

Couple of weeks ago I was writing JavaScript, while unit testing I came across very strange bug that I could not figure it out. The number I was trying to parse was "08", when I used parseInt without radix I got the result "0"

parseInt("08") --> returned "0"
parseInt("0222") --> returned "146"
parseInt("08", 10) --> returns "8"
parseInt("0222", 10) --> returned "222"

The reason for this strange phenomenon lies in radix. Syntax for parseInt is parseInt(string, radix), where string part is required and radix is optional. When you don't provide radix, JavaScript tried to determine radix from given sting.

if your string begins with "0", it assumes radix is 8(octal)
if your string beings with "0x", it assumes radix is 16(Hex) otherwise it will assume that radix is 10 (decimal)

If you don't specify radix and if you are certain that string that will be parsed using parseInt will never have "0" as leading character then I would say skipping radix parameter is fine.

Wednesday, March 04, 2009

HTML <label> tag

Are you using <span> or <div> tag instead of using <label>? Well you are not alone.

for the longest time whenever I wanted to use radio button, checkbox, textbox, or textarea i used <span> tag, I also used add “onclick” on span when ever I used it with radiobox or checkbox so it would give check or uncheck in the case user click on <span> tag

<input id="rdoTentative" type="radio" name="confirmtype" value="T" /><span onclick="document.getElementById('rdoTentative').checked = true;">Tentative</span>

But instead this little tag takes care of onclick event for me when using <label>

<input id="rdoTentative" type="radio" name="confirmtype" value="T" /><label for="rdoTentative">Tentative</label>

or you can do following

<label><input id="rdoTentative" type="radio" name="confirmtype" value="T" />Tentative</label>

for more detailed reading please visit W3CSchool site.

Tuesday, March 03, 2009

Using JQuery Clearing Form

Few days back I download JQuery’s UI Plug-in which came with bunch of nifty UI’s, however the one particular I was interested in was “Dialog box” plug-in.

After playing with it a little bit I realized that I need to clear the form after I close, and process the dialog box's form information. So I searched for built-in JQuery function that can do that but no luck. So, after searching just little bit I came across this page http://www.learningjquery.com/2007/08/clearing-form-data. Well the article did really nice job explaining, but the solution give in this article did not work, however after reading comments on that page I saw one comment with following piece of code that work perfectly for me.

//this is to Clear All the field with in perticular Element
$.fn.clearForm = function() {
  $( this ).
    find( ':text, :password, textarea' ).
      attr( 'value', '' ).end().
    find( ':checkbox, :radio' ).
      attr( 'checked', false ).end().
    find( 'select' ).
      attr( 'selectedIndex', -1 );
};

Dialogbox opens new window on pressing enter key in Textbox

Recently I have encountered strange issue. Every time I press "enter" key in to the textbox of opened dialogbox it opens up new browser window. I even tried putting below code on onKeyPress event, but it didn't work. var charCode = (evt.which) ? evt.which : event.keyCode if(charCode == 13){ event.cancelBubble=true return false; } finally after long research on Google, I came across where I found that the reason this was happening is because if Dialogbox has only one textbox then it automatically tries to submit the form, so in my case in dialogbox it was opening new window while trying to submit the form. Resolution I found from above site was to put another textbox, weather its visible or hidden its not a problem. so if this happens in your dialogbox just add below code <INPUT type="text" style="VISIBILITY: hidden;POSITION: absolute">