Archives

Articles tagged ‘javascript’

Quick Tip: Do you miss the target?

Opening links in a new window was once quick and easy but since the target="_blank" options on a links have died (if you didn’t knew, I’m very sorry to be the one telling you this) the only way left was the javascript way.
Read the full article

Quick Tip: JavaScript integers parsing

I’ve came across a strange problem when trying to parse date parts (2009 01 21) as integers in a form validation script. Somehow my month being parsed as 0 (zero) and not as 1 (one) as supposed to be. Strange. I’ve googled around and discovered that JavaScript’s parseInt support different (not so many) number bases and by default it “guesses” the base you are trying to work.

Sure, he found the “01″ and thought “Oh yeah babe, it’s an octal number!” — wrong my friend, it’s just a zero-padded number, sorry disappointing.

So, I had to supply the second argument called radix as 10 (decimal) that is indeed the base you are going to use. Setting this makes parseInt to respect you instead of having his free-will.

So I ‘ve got:

var _orderDateMonth = parseInt($('#survey_order_date_month').val(),10); // decimal base!

NOTE: The dollar sign ($) and .val() are specific JQuery functions.

NOTE: I personally hate when people break up the date parts into different inputs. If you are already going to use JavaScript, implement a damn date-picker!