Wednesday, July 16, 2014

Disable right click on image using jQuery

In this article i am going to explain how to disable right click on image using jQuery.Disable right click function is used to avoid copying images,websites and codes.


Live DemoDownload Script


contextMenu is used to trigger contextMenu with right-click, left-click, hover or own custom trigger events.
   
    Step 1:
    Need library function.Just copy and paste the below library file.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

jQuery Function

$(function() {
        $('img').bind("contextmenu", function() { //It works for all img tags.
            return false
        });
    });

HTML code for disable right click

 <img src="your-img.jpg" alt="img" />

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

Preview Image before upload using jQuery

In this article i am going to explain how to Preview Image before upload using jQuery.I have used html file upload method in this example.This preview image before upload method is very useful to see uploaded image is correct or not.



FileReader() is used to read the contents of a file.

jQuery Function

function showimagepreview(input) {
      
            if (input.files && input.files[0]) {
                var reader = new FileReader();
      
                reader.onload = function (e) {
                    $('#imgview').attr('src', e.target.result);
                }
  
            reader.readAsDataURL(input.files[0]);
            }
    }

onload() function is used to execute javascript after page load is finished.
attr is used to set values of select elements.
target is used to returns the element that triggered the event.

HTML file upload

<form name="imageupload" action="#" enctype="multipart/form-data">
  <input type="file" name="imgupload" id="imgupload" onChange="showimagepreview(this);" />
</form>

Preview image before upload

<img id="imgview" style="max-width: 160px; max-height: 120px; border: 1px solid #ccc;"/>

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

Monday, July 14, 2014

Add style for html5 placeholder using CSS

Placeholder:
The placeholder is used to specifies a short hint for an input field.It is new HTML5 tag.

Let's take a look how to add style for placeholder.

Syntax

<input placeholder="Your Text goes Here"/>

CSS

#input::-webkit-input-placeholder {
            color:#09F;
        }
        #input:-moz-placeholder { /* Firefox 18 and older */
                color:#09F;
        }
        #input::-moz-placeholder {  /* Firefox 19+ */
                color:#09F;
        }
        #input:-ms-input-placeholder {
                color:#09F;
        }

HTML File

<input type="text" id="input" placeholder="Name"/>

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

Friday, July 11, 2014

Download file after form submit in PHP

In this article i am going to explain how to download after form submitted in PHP.There are two ways available to download file using php.In this example i have used both methods.

1.Using PHP
2.Using Javascript and meta tag.


readfile() is used to Outputs a file.

PHP Function

$file="test.zip";
        header('Content-type:  application/zip');
        header('Content-Length: ' . filesize('test.zip'));
        header("Content-Disposition: attachment; filename='test.zip'");
        readfile($file);

Javascript function

<script>
    $(document).ready(function(){
      window.setTimeout(function(){
        window.location = 'test.zip';
      }, 1500);
    });
    </script>

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

Thursday, July 10, 2014

Show or Hide Password using jQuery

In this post i want to explain how to Show or Hide Password using jQuery.In this example i have used show() and hide() methods.This method is very useful to check wheather entered password correct or not.


Before that we need to include jQuery Library file.Copy and Paste the following URL.
Library File:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script>

jQuery Function

 <script type="text/javascript">
    $(function () {
        $('#show').hide();
      
            $('#btn').click(function () {
                var txt = $('#btn').val()
                var pwd = $('#hide').val();
                if (pwd.length > 0) {
                    if (txt == 'Show Password') {
                        $(this).val('Hide Password');
                        $('#show').val($('#hide').val());
                        $('#show').show();
                        $('#hide').hide();
                        return false;
                    }
                else if (txt == 'Hide Password') {
                    $(this).val('Show Password');
                    $('#show').hide();
                    $('#hide').show();
                    return false;
                }
            }
            else {
                    alert('Plese Enter Password');
                    return false;
                }
        });
    })
</script>

HTML File

<form>
          <div> <b>Enter Password: </b>
            <input type="password" id="hide" />
            <input type="text" id="show" />
            <input type="button" id="btn" value="Show Password" />
          </div>
     </form>


Please share your comments and feedback.Thanks.Please subscribe my updates via email.

Saturday, July 5, 2014

Display current time on webpage using Javascript

In this post i want to explain how to Display current time on webpage using Javascript.In this example i have used date and toLocaleTimeString methods.

toLocaleTimeString:
Return the time portion of a Date object as a string, using locale conventions.

Date():
The Date object lets us work with dates.

A date consists of a year, a month, a week, a day, a minute, a second, and a millisecond.

Date objects are created with the new Date() constructor.

There are 4 ways of initiating a date:
new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)

setTimeout:
Display an alert box after xx seconds


Live DemoDownload Script

Before that we need to include jQuery Library file.Copy and Paste the following URL.
Library File:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script>

jQuery Function

<script type="text/javascript">
            function ShowTime() {
                var dt = new Date();
                document.getElementById("time").innerHTML = dt.toLocaleTimeString();
                window.setTimeout("ShowTime()", 1000); // Here 1000(milliseconds) means one 1 Sec
            }
        </script>

HTML File

<label id="time" style=" font-weight:bold"></label>

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

Useful Animation jQuery CSS3 Examples

1.CSS/SVG Animated Circles
2.Endless jQuery Gallery Animation
3.Drawing Advanced animation path
4.CSS3 Parallax Fighter Jet Animation from MySkins Studio
5.CSS3 Flat Circle/Round Icon Animation
6.Animating with setTimeout
7.jquery animation effect
8.Earth orbit CSS animation
9.CSS3 Animated Bird Fly
10.CSS3 Atom Animation
11.CSS jQuery 3D Solar System
12.Pure Animated CSS birthday cake