Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, July 11, 2013

How to disable some context menu items on Telerik TreeView

There is an event named "OnClientContextMenuShowing" for Rad Treeview that calls javascipt function and passes 2 arguments "sender, args".
The Args parameter contains The current selected TreeNode and Context Menu Items.
You can enable or disable any Context menu item based on any attributes for the Current Selected Tree Node.

Here is a code snippet for the javascript function that demonstrate how can you get the current select Tree Node and the Context menu Items and how can you disable the items.
function onClientContextMenuShowing(sender, args) {
            var treeNode = args.get_node();
            if (treeNode._attributes != undefined) {
                if (treeNode._attributes._keys[0] == 'BoolFlag') {
                    // 0 refer to the Context Menu item index
                    args.get_menu().get_items().getItem(0).set_enabled(false);
                    args.get_menu().get_items().getItem(1).set_enabled(false);
                    args.get_menu().get_items().getItem(3).set_enabled(false);
                }
            }
        }

Tuesday, January 1, 2013

How to avoid Uncaught ReferenceError: $ is not defined in jQuery

Sometimes while developing an existing Web Application, I wanted to use jQuery function and I get this error "Uncaught ReferenceError: $ is not defined".

There are some reasons causing it and ways to avoid them:
  • Make sure the references to the jQuery scripts is loading first, but them in the head of master page or the page you are using.
  • Sometimes the references to the jQuery scripts is loading twice, make sure it loads only once.
  • If you have external js files with your function, which depend on other jQuery libraries, you have to load that library first, and then dependent JS file with your functions.
Example:

This will not work:
<script src="customlib.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
But this will work:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="customlib.js"></script>

Wednesday, February 15, 2012

How to Submit a Form Using JavaScript

Any form is submitted when the user click on the submit button.
But you may need to submit the form programmatically using JavaScript.
JavaScript has the form object that contains the submit() method.
Use the "ID" of the form to get the form object.
Example:
If the name of the form is "Form1", JavaScript code for the submit method is:
document.forms["Form1"].submit();

Sunday, January 1, 2012

Javascript Regular Expression to match a comma delimited list

This method uses the JavaScript String's match() method to parse a comma delimited list and show its content in a Panel control.

You can try it here http://jsfiddle.net/38tXU/
function parseList(list) {
    var reg = list.match(/\w+(,\w+)*/g);
    document.getElementById('pnl').innerHTML = 'Total length:' + reg.length + '<br />';
    for (var i = 0; i < reg.length; i++) {
        document.getElementById('pnl').innerHTML += 'Token:\'' + reg[i] + '\'<br />';
    }
}
//Call parseList function
parseList('item1, item2, item3');

Tuesday, August 19, 2008

How to Ignore JavaScript errors

Sometimes when you are working on a page and want to publish it and you have some JavaScript errors, but you don't have time to debug it, you can put the following code in order to ignore the JavaScript errors:
<head>
<script language="javascript">
    function stoperror() {
        return true;
    }
    window.onerror = stoperror();
</script>
</head>

Saturday, July 5, 2008

JavaScript Code In Address Bar!

Go to Google.com choose Images and type Flowers, press search images button then copy and past this code in your browser Address Bar then press enter and Enjoy!

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);

Note:
You can do this with any page has photos in it.