Author Archive

Required Field Validation

One of the important use of JavaScript is Client Side Validations. We can validate the form’s data before sending to the server. example: Required Field Validation (can’t leave the field blank) <html> <script> function validate() { var name = document.myForm.txtName; if(name.value.trim()==””) { alert(“Please enter name”); name.focus(); return false; } else { return true; } }

“this” Keyword

“this” refer to the object on which a method is being invoke. We can pass “this” as an argument in function, as in given examples: example 1 <html> <head> <script type=”text/javascript”> function focusTr(objTr){ objTr.style.background =”yellow”; objTr.style.color =”red”; } function unFocusTr(objTr){ objTr.style.background =”white”; objTr.style.color =”black”; } </script> </head> <body>

Populate Div with JavaScript

We can fill div dynamically with the help of JavaScript, using innerHTML. As the example given below. <html> <head> <script type=”text/javascript”> function fillDiv(){ var sub = document.getElementById(‘msgDiv’); var txtVal = document.getElementById(‘txt’).value; sub.innerHTML = “Entered Text is “+txtVal; } </script> </head> <body> Enter Text : <input type=’text’ id=”txt”/> <input type=”button” onclick=”fillDiv()” value=”Show”/> <div id=”msgDiv”> </div> </body>

Customize the WordPress Search

We can change the design and add additional fundability in the search widget provided by WordPress. Make a file “searchform.php“ in your theme folder and add the blow given code. You can also add your style or script as need in this file. <?php /** * The template for displaying Search Results pages * *

Filter Search In WordPress

We can filter our search in WordPress according to posts or custom post. Like I have two custom posts type videos and news and I want WordPress search page will display records out of only these 2 custom posts whenever user search record. So to achieve this we have to write this code in our

Disable Updates in WordPress

To disable the update in WordPress Write these lines in functions.php of your theme folder. To Disable Theme Updates # 3.0+ remove_action( ‘load-update-core.php’, ‘wp_update_themes’ ); add_filter( ‘pre_site_transient_update_themes’, create_function( ‘$a’, “return null;” ) ); wp_clear_scheduled_hook( ‘wp_update_themes’ );

document.getElementsByName

getElementsByName() is a method in JavaScript through which we can accesses all elements with the specified name. Example : <html> <head> <script type=”text/javascript”> function getbyNameDemo(){ var sub = document.getElementsByName(‘rbtnSubjects’);

Textbox in CakePHP

Following are the methods through which we can create Textbox in CakePHP. Example 1: echo $this->Form->input(‘usrUsername’); Above code will render following output in view: <div class=”input text”> <label for=”UserUsrUsername”>Usr Username</label><input name=”data[User][usrUsername]” type=”text” id=”UserUsrUsername”/> </div>

Custom Post in WordPress

In below example I have added 2 custom posts in WordPress (with different parameters) Videos News Add the following code in functions.php and it will create menu in admin panel for videos and news. add_action( ‘init’, ‘create_post_type’ ); function create_post_type() { register_post_type( ‘my_video’, array( ‘labels’ => array( ‘name’ => __( ‘Videos’ ), ‘singular_name’ => __(

Create a Form in CakePHP

To create a form in CakePHP we can use careate() method. Let’s take an example with cake1 as a root folder and users is a table. <?php echo $this->Form->create(); ?> Above code will render following output in view: <form action=”/cake1/users/” id=”UserIndexForm” method=”post” accept-charset=”utf-8″> In create function parameters are optional. If we call this function without