Skip to main content

Posts

Showing posts with the label Javascript

Show Current Time via JavaScript

This Code will show client side current time.  You just have create a div with a JavaScript function call as shown below. js_clock(); JavaScript Function: function js_clock() { var clock_time = new Date(); var clock_hours = clock_time.getHours(); var clock_minutes = clock_time.getMinutes(); var clock_seconds = clock_time.getSeconds(); var clock_suffix = "AM"; if (clock_hours > 11) { clock_suffix = "PM"; clock_hours = clock_hours - 12; } if (clock_hours == 0) { clock_hours = 12; } if (clock_hours < 10) { clock_hours = "0" + clock_hours; } if (clock_minutes < 10) { clock_minutes = "0" + clock_minutes; } if (clock_seconds < 10) { clock_seconds = "0" + clock_seconds; } var clock_div = document.getElementById('js_clock'); clock_div.innerHTML = "<strong>" + clock_h...

Max Length not working for Multi Line Text Box : Solution

In almost all the web projects, we require a multiline TextBox control. It was annoying to find that maxLength property doesn't work on multiline textboxes. There is a workaround to accomplish this using RegularExpressionValidator. Following is the markup that will restrict the text box to maximum of 500 characters. OR You it can be done so easily using javascript functions. I suggest that we should put a javascript validator function so that user will not be able to enter characters more than the length specified, even cant paste any text with more than specified characters. Here are those javascript functions. TextBox Control Javascript: // Keep user from entering more than maxLe...

document.createElement not working on Firefox

document.createElement not working on Firefox Javascript method document.createElement() worked perfectly in all browsers other than FireFox. I changed this part 1: var newElement = document.createElement( "<input name='" +elementName+ "' id='" + elementName + "' type='hidden'>" ); to this: 1: var newElement = document.createElement( "input" ); 2: newElement.setAttribute( 'name' ,elementName); 3: newElement.setAttribute( 'id' ,elementName); 4: newElement.setAttribute( 'type' , 'hidden' ); and now its working with all browsers