background preloader

JavaScript & JQuery

Facebook Twitter

jQuery UI. JavaScript, SharePoint, and the getElementById Blues - Eric Shupps. It doesn't take long for anyone who does client-side coding in SharePoint to figure out that the trusty ol' getElementById() method just ain't all it's cracked up to be.

JavaScript, SharePoint, and the getElementById Blues - Eric Shupps

Sure, it works fine in standard ASP.NET pages but in SharePoint all that pretty client-side code goes right out the window. Just what is going on here? The simple answer is that SharePoint is coming between you and your control ID's. Keep in mind that a typical SharePoint page may have dozens of individual server controls, user controls, field elements web parts, and other objects scattered throughout the page hierarchy.

In order to maintain viewstate for all these elements, SharePoint must translate simple, easy-to-read ID's into something that it can be sure is unique, as it has no way to determine if that same control ID might exist somewhere else on the page. $PersProviderGeneral.ascx$SubNavBase1$General$fvFormView$txtTextBox1'. Instead of this: document.getElementById('txtTextBox1'); You'll need to do this: HowTo: including default text in a Textbox while enforcing server-side validation - Jason Salas' WebLog. I was asked recently to develop a process wherein a server-side TextBox control could have some default text included in it, which seems to be more and more the reliable UI model for ensuring people fill out required form fields.

HowTo: including default text in a Textbox while enforcing server-side validation - Jason Salas' WebLog

The kicker is that the app in which it runs still needs to enforce server-side validation, meaning that the TextBox would need input data other than the said default value, and not have the default text erroneously have the form be seen as valid. This is quite easy to do if done all on the server, however doing so usually requires handling the OnTextChanged event, which forces a server roundtrip which is largely unnecessary.

The code below displays a single TextBox control, with the given value "(enter something here)". Note how the ONFOCUS and ONBLUR events are handled on the client in JavaScript routines for cases when the TextBox becomes the active or inactive form element, respectively. Using the Built-in Silverlight Media Player of SharePoint 2010. JavaScript date and time and getting the current year, month and date with the JavaScript date object. Format #3: date-month name-year (something like, 21-March-2001) The getMonth() function gives us the month in a numeric form.

JavaScript date and time and getting the current year, month and date with the JavaScript date object

To convert this value into the month name, we will employ an array. The array would contain all the 12 month names. Note: For the sake of clarity, I've written the JavaScript code for the array in multiple lines. For usage, you would have to put this on a single line. This time, we use the new operator with the Array() constructor and store the 12 month names in the array. The code above prints: 8-April-2014 Format #4: Like 21st March 2001 In this format we include a superscript to the date value.

<script type="text/javascript"><! Note: The last line of code has been split up into two lines. We first initialize a variable sup that would store the superscript value. The code prints: 8th April 2014 Page contents: JavaScript date and time and how to obtain the current year, month and date on the visitors computer using the JavaScript built-in Date() object. The JavaScript Source: Forms : Auto Currency.