-->

Sunday, November 9, 2014

Commonly used jQuery Event Methods: jQuery

All the DOM events have its equivalent jQuery methods that may be implement by programmer as per the requirement. Anything happens through input devices on the web-page is called an event.

All these events have its unique names e.g. clicking on the page, pressing key, hovering mouse etc. According to jQuery masters, these events have some categories, some of them listed below:

  • Keyboard events: KeyDown, KeyUp and KeyPress etc.
  • Mouse events: Click, double click, mouse hover, mouse enter and mouse leave etc.
  • Form events: submit, focus, blur etc. 
  • Document/window events: Load, UnLoad, scrolling, resizing etc.

All these events have its own method, discussed earlier in changing default behavior. Some of those events have listed below with example:

$(document).ready()

Whenever the document/page is ready, this event have triggered. Anything written in this event have been executed just after the page loaded. All the events except functions must be written in this event to be executed. Some of the selectors have been discussed here.
$(document).ready(function(){
alert(‘document is ready’); // This message will shown just after the page load its contents.
});

click()

This event triggers when user clicks on any html events. Programmer can write particular click method on any html event. The below code will execute when user clicks on any <p> element.
$(“p”).click(function(){
alert(‘p tag clicked’);
});

dblclick()

This event triggers when user double clicks on any html events. Programmer can write particular double click method on any html event. The below code will execute when user clicks two times on any <p> element.
$(“p”).dblclick(function(){
alert(‘p tag double clicked’);
});

mouseenter()

This event triggers when user enters mouse in the area of html events. The below code will execute when user enters into area of any <p> element.
$(“p”).mouseenter(function(){
alert(‘mouse entered in <p> tag’);
});

blur()

whenever an html event losses its focus, this event will triggered. This is just opposite event of focus() event which triggers when an element have focus on it.
$(“p”).blur(function(){
alert(‘losses focus from <p> tag’);
});

There are many events related to each html element, can be read from jQuery official website of through the help option of visual studio. All those events have similar syntax to write method for them. In the next article we will discuss about jQuery effects.

Saturday, November 8, 2014

Merits of bottom-up technique


  • The details of the sub-problem solutions are available in advance in the form of bottom level modules.
  • The individual sub-problem solutions are designed with great details.
  • The main solution can be planned later depending on the available sub-task solutions.
  • The main solution is used to link all the sub-problem solutions.
  • The sub-solutions obtained are simple
  • A complex main module is designed later using these simpler solutions.
  • This technique is more general and code are reusable.
  • This technique simplifies maintenance and the new features can be added easily.
  • This decision of the final solution can be delayed to make it more effective for implementation.
  • Testing in this case is simple and test cases can be designed very easily.

Demerits of top-down technique


  • This technique is mainly useful for small-scale problems.
  • It is only useful in solving a part of a larger problem.
  • This technique is a poor approach for solving larger problems 
  • This technique is also poor for designing larger programs.
  • The application developed using this technique cannot be upgraded easily.
Related Links





Merits of top-down technique


  • The summary of the program plan is known in advance in the form of top module.
  • Parallel development of the program is possible because of independent design of the modules at different levels.
  • Parallel development helps in designing the program at reduced time period.
  • Testing and debugging are faster because of independent testing of modules.
  • Attention can be given to individual level task to improve the efficiency.
  • The hierarchy of the levels helps in understandable low level modules.
  • Handling and management of the modules are easy.
  • This technique improves the code reliability.

Features of top-down technique


  • Program preparation is stretched to a number of levels 
  • In place of writing long list of statements, the statements are separated into different modules at various levels.
  • The stretching is most general to most specific.
  • Program is structured as hierarchy of various tasks.
  • As the techniques moves from top to bottom, it is a type of specialization.
  • Main module can be designed well before without requiring details of complete design.
  • Testing can be done after inserting down level modules one-by-one.
  • Parallel development is possible because of top and down level modules design.

Rules for making Flowchart

"What are the rules for making the flowchart?"

Rule 1: The flowchart should contain one start and one stop box (terminator).
Rule 2: The symbols of the flowchart are always labeled with simple codes.
Rule 3: The codes used in the flowchart should not give more than one meaning.
Rule 4: The control flows are always represented by directed arrows.
Rule 5: The control flow lines touch the boundary of any box either while leaving from or while entering into the box.
Rule 6: The control flow lines should not cross each other.
Rule 7: The flow line moves in vertical direction either from top to bottom or from bottom to top.
Rule 8: The flow line moves in horizontal direction either from left to right or from right to left.
Rule 9: Only one flow line comes out from all the boxes or symbols excepts decision box.
Rule 10: Two lines can flow from the decision box if single condition is checked. It means a single condition results in one of the two values TRUE or FALSE

Design an algorithm to search a number using binary search technique

Binary Search algorithm is applied where we want to search number in sorted numbers. In this algorithm, first to find mid position of the list and divide the list into two parts. If number is equal to mid then position find easily , this is the  best case of binary search.
Problem: Design an algorithm to search a number using binary search technique.
Input : A list (array) of numbers in ascending order, number of elements in the list and key to search.
Output: Returns 1 if the key is found otherwise returns 0

BIN_SEARCH(LIST, N, KEY)
[LIST is an array of numbers in ascending order]
[N is the size of the array and KEY is the number to search]
L <-- 0;  H<-- N-1;  [Assuming that array index start from 0]
M <-- INT ( (L+H) /2 ) [Get the quotient or integer part after division]

Repeat While (L <= H)
If(Key == LIST[M]) then:
Return 1                [Key found]
Else:
If(Key < LIST[M] ) then:
H <-- M-1                     [Move to the left half of the list]
Else:
H <-- M+1                    [Move to the right half of the list]

        [End of If]
     [End of If]
  [End of While]
  Return 0                                         [Key not found]
  Exit.
© Copyright 2013 Computer Programming | All Right Reserved