Posts

Showing posts from September, 2007

The importance of JavaScript 'return'

Recently, while coding for a Text Field value padded with left zeros, realised the importance of the RETURN key word for the FUNCTION written in JavaScript. Before i mention the actual importance, let me describe you the situation. Scenario: A Text box need to be padded with zeros and should have the length of 7 digits, even the data entered is less than 7. Ex: When the key board input being 88, the text box should show 00000 88. Note the ZEROs padded on left. So, started with a JavaScript function as mentioned below function PadZeros(x) { var v = x.value; while (v.length<7) { v = '0' + v; } var ss = document.getElementById(x.id); ss.value = v; } After this, the text box is padding with ZEROs and the code is perfectly running. To allow this to code execute for any given text box, all you have to do is, add the ATTRIBUTE to that text box. And while adding keep one thing in mind that, we would be calli