Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Wednesday, December 05, 2012

Functions vs. Methods in JavaScript with Encapsulation!

Hi Folks,

I found something interesting to share with all of you in Javascript. Functions in javascript as we all know is defined with function keyword while Method in Javascript is a function but can have a scope and you can hide it as we do in object oriented programming. I will be showing 2 examples that implement function versus method in your web page to add 2 numbers.

1) Function to add 2 numbers in Javascript:

In your script tag, this is the declaration of the function:

<script language=javascript >
function myfunction() {
document.getElementById('txtResult').value = parseInt(document.getElementById('Text1').value) +                                             parseInt(document.getElementById('Text2').value);
</script>

My page, see the result after you change the second text box:

<p>Using Functions</p><input type="text" id="Text1" /><br /><input type="text" id="Text2" onchange="myfunction();" /><br /><input type="text" id="txtResult" /><p>

2) Method to add 2 numbers using Methods:

<script language=javascript >
// Methods
var ops = {

add: function AddTwoNumbers() {
                              document.getElementById('txtResult2').value =
                              parseInt(document.getElementById('Text3').value) +
                                 parseInt(document.getElementById('Text4').value);               
                                               }
         };</script>

My page:

<p>Using Methods</p><input type="text" id="Text3" /><br /><input type="text" id="Text4" onchange="ops.add();" /><br /><input type="text" id="txtResult2" />

You will see that we implemented the add function that has the scope within ops object, and in this way you can design and organize your functions within different scopes and with that being said you implement encapsulation for your methods!.

Anoter note, you gave an alias to your function with "add" alias name and this is not the actual name of the method since if you try to call the method as AddTwoNumbers you won't be able to do that.

The running application:



Hope this helps!

Wednesday, June 09, 2010

SharePoint 2010 development errors and fixes

Hi Folks,

I want to share 2 errors i was getting while working with the ECMA Javascript Client Object Model in SharePoint 2010.

Error #!: only content controls are allowed directly in a content page that contains content controls. script

Why : when you have script block outside the content controls in your application pages in sharepoint 2010.

Solution:
Add your Script block on the PlaceHolderAdditionalPageHead
In your application page.

Error #2: Cannot make a cache safe URL for "1033/sp.debug.js", file not found. Please verify that the file exists under the layouts directory.

Why this happen? Because SP.debug.js doesn't exist under layouts folder in sharepoint 2010.

Fix: Copy your SP.debug.js from this file path:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS

and paste it on the following directory:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033

Hope this helps.



Regards,
Mostafa arafa

Thursday, July 30, 2009

Learn how to build interactive WCM portal in sharepoint

Hi folks,

Excellent video by Technology Director of Razorfish, he shows how can you build interactive content management portal in sharepoint using jQuery,Ajax,Silverlight and flash ?

The video also shows how to enable RIA features/Web 2.0 in your sharepoint enterprise portal using flash and silverlight and social networking.

The video is full of best practices and initiative ideas.....

Enjoy watching this video:

http://videos.visitmix.com/MIX09/C19F


-- Mostafa Elzoghbi

Monday, June 29, 2009

Get started with jQuery library from its own creators !!!

Hi Folks,

As you know, MS announced that jQuery is a built-in library in VS 2008 SP1 for ASP.NET Developers.

I recommend for all developers, to see the series of jQuery Library videos from its own creator : John Resig and his team, this series of videos help you to understand the jQuery library features,jQuery UI and other important notes for advanced developers.

I enjoyed watching these series, and i suggest all of you to understand and start using jQuery library in your .NET Projects and solutions.

After you finish this series, i like to share with you these posts for integrating ASP.NET with jQuery library:

1) ASP.NET with jQuery: Scott hanselman:
http://www.hanselman.com/blog/jQuerytoshipwithASPNETMVCandVisualStudio.aspx
2) ASP.NET with jQuery:
http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx

Hope this helps.

Regards,
Mostafa arafa

Friday, November 07, 2008

jQuery ? New easy life for web developers

Hi All,

For all web developers,new library which ease your life to write javascript code and it is also integrated with VS.Net IDE. if you have your asp.net application or Ajax enables asp.net application you can now download an integrate jQuery with your existing web application or website.

jQuery gives you a great advantage of manipulating your html elements by providing an API selector with the intellisense in VS.Net.

Read more and the download link of jQuery Library :
http://jquery.com/

How to integrate jQuery in your asp.net application:
http://www.hanselman.com/blog/jQuerytoshipwithASPNETMVCandVisualStudio.aspx

Scott Gu announcing the jQuery integration with VS.Net :
http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx

Happy .Net programming :)







Regards,
Mostafa arafa