Recent Articles
Showing posts with label Javascript/Jquery. Show all posts
Showing posts with label Javascript/Jquery. Show all posts

Monday, January 6, 2014

Easy to use Bootstrap Date Range Picker

Monday, January 6, 2014 - 0 Comments

Hiiii, Being a developer ,many times it happen that you need a date picker on your website mainly on forms. jQuery has provide a very simple date picker to apply on input fields but that date picker is not so attractive CSS wise and it selects only a single  date. What if you want to select both "from date" and "to date", "from date" and "to date" with time or you want to select dates like : yesterday date, last seven days, last month.For the selection of these different types of date, Bootstrap has introduced a daterange picker to provide all the above discussed functionality and one more good thing about this daterangepicker is that it looks attractive due to bootstrap CSS.
So, in this post ,I will be giving a one by one demo of three different types of date range pickers with one picking just "from date" and "to date", second one will also choose the time and third one will select dates like last month, last week, yesterday,etc.

To run the tutorials given below , download the complete set of Javascript and css from here.

Fistly, include all the Javascript and CSS files in this package from the link above and some extra files needed for this tutorial in your code as shown below :
 <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
 <link rel="stylesheet" type="text/css" media="all" href="daterangepicker-bs3.css" />      // Provided in the package
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
 <script type="text/javascript" src="moment.js"></script>      // Provided in the package
 <script type="text/javascript" src="daterangepicker.js"></script>      // Provided in the package 



Date Range Pickers:

1. Simple Date Range Picker:

This is just a date picker which gives you a functionality of just adding "to date" and "from date". This is very easy to implement and it is just applied by giving id attribute to an input field and then applying a daterangepicker on that particular id. Code and screen shot as given below : 

Simple Date Range Picker:


<form class="form-horizontal">
  <fieldset>
    <div class="control-group">
      <label class="control-label" for="selectdaterange">Select Date Range:</label>
      <div class="controls">
        <div class="input-prepend">
          <span class="add-on"><i class="icon-calendar"></i></span><input type="text" name="selectdaterange" id="selectdaterange" />
        </div>
      </div>
    </div>
  </fieldset>
</form>
 
<script type="text/javascript">
$(document).ready(function() {
    $('#selectdaterange').daterangepicker();
});
</script>


2. Date Range Picker with Time :

This is a date range picker which gives you an additional functionality of adding a Time  with that provided by the simple Date Range Picker. This is also easy to implement and is implemented in the same way as the Date Range Picker shown above by applying it on form input field. Code and screen shot as given below : 

Date Range Picker with Time

<form class="form-horizontal">
  <fieldset>
    <div class="control-group">
      <label class="control-label" for="dateandtime">Reservation dates:</label>
      <div class="controls">
        <div class="input-prepend">
          <span class="add-on"><i class="icon-calendar"></i></span><input type="text" name="dateandtime" id="dateandtime"/>
        </div>
      </div>
    </div>
  </fieldset>
</form>
 
<script type="text/javascript">
$(document).ready(function() {
  $('#dateandtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' });
});
</script>


3. Date Range Picker With Custom Dates :

This is a date range picker which gives you a functionality of choosing different types of date range like last month , last week, yesterday etc. It is somewhat easy and may be difficult for those who are unaware of jQuery implementation as this date range picker is not applied to form input field rather it is implemented on some div but to enter the value of date selected to the form input values, you have to use jQuery. Code and screen shot as given below : 

Date Range Picker With Custom Dates

            <h4>Select Date Range With Options</h4>

            <div class="well" style="overflow: auto">

               <div id="reportrange" class="pull-left" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
                  <i class="glyphicon glyphicon-calendar icon-calendar icon-large"></i>
                  <span></span> <b class="caret"></b>
               </div>

               <script type="text/javascript">
               $(document).ready(function() {
                  $('#reportrange').daterangepicker(
                     {
                        startDate: moment().subtract('days', 29),
                        endDate: moment(),
                        minDate: '01/01/2012',
                        maxDate: '12/31/2014',
                        dateLimit: { days: 60 },
                        showDropdowns: true,
                        showWeekNumbers: true,
                        timePicker: false,
                        timePickerIncrement: 1,
                        timePicker12Hour: true,
                        ranges: {
                           'Today': [moment(), moment()],
                           'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
                           'Last 7 Days': [moment().subtract('days', 6), moment()],
                           'Last 30 Days': [moment().subtract('days', 29), moment()],
                           'This Month': [moment().startOf('month'), moment().endOf('month')],
                           'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
                        },
                        opens: 'left',
                        buttonClasses: ['btn btn-default'],
                        applyClass: 'btn-small btn-primary',
                        cancelClass: 'btn-small',
                        format: 'MM/DD/YYYY',
                        separator: ' to ',
                        locale: {
                            applyLabel: 'Submit',
                            fromLabel: 'From',
                            toLabel: 'To',
                            customRangeLabel: 'Custom Range',
                            daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr','Sa'],
                            monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                            firstDay: 1
                        }
                     },
                     function(start, end) {
                      console.log("Callback has been called!");
                      $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                     }
                  );
                  //Set the initial state of the picker label
                  $('#reportrange span').html(moment().subtract('days', 29).format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));
               });
               </script>

            </div>

This above defined Date Range Picker with options doesn't apply on input fiield as it is applied on <div> so to use the values of the dates selected with options in this div, we have to insert the values of the selected date to the hidden input fields in the form and then when you submit that form , then you can use that values via GET or POST method to get the data. So you have to update the above provided code with the modied code a shown below :

Firstly you have to create to hidden input fields as shown below :
<input type="hidden" name="to" id="to" value="">
<input type="hidden" name="from" id="from" value="">

Secondly you have to update the  function (start, end) highlighted above to the function as shown below :
function(start, end) {
                      console.log("Callback has been called!");
                      $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
       $('#to').val(start.format('MMMM D, YYYY'));
       $('#from').val(end.format('MMMM D, YYYY'));
                     }



Hope you like this post……..Please Comment…………!!!!!!!!!

Wednesday, December 18, 2013

Different Types of AJAX Usage with Examples

Wednesday, December 18, 2013 - 0 Comments

Hiiiii, Being a web developer, you have used ajax many times for submitting form and then serializing the data of form to send the data on the same page or on a next page.
You may used this ajax with many different syntax like : you have used dataType:"json" before data sending or you may have used "parsed_data = jQuery.parseJSON(data)" after the don or success function after getting the response.
Some people use these different syntax without being aware of the meaning of these different syntax.
So, here in this I'll be showing two examples explaining the difference between these two syntax and usage.

AJAX USAGE

AJAX USAGE 1 :

 $.ajax({  
 type: "POST",
 url: "post1.php",
 data: // YOUR DATA TO SEND 
 }).done(function( data ) {

 parsed_data = jQuery.parseJSON(data);
 alert(parsed_data.response1);
 alert(parsed_data.response2);    
});

AJAX USAGE 2 :

 $.ajax({  
 type: "POST",
 url: "post1.php",
 dataType: "json",
 data: // YOUR DATA TO SEND
 }).done(function( data ) {
    
 alert(data.response1);
 alert(data.response2);    
});

In the Ajax usage 1 we haven't used dataType:"json" and rather we have used parsed_data = jQuery.parseJSON(data) in the response function of ajax when response is received through ajax . We have used this jQuery.parseJSON(data) to decode and parse the encoded JSON which is received in ajax response from the page on which you sent the data. The encoded  JSON response which you will getting in response for both the usage of ajax shown here will be of the form : 

{"response1":"Hello","response2":"World"}

After using this jQuery.parseJSON(data) as shown in Ajax Usage 1 , you can use the value of each of the variables in response JSON by :

data.response1 , data.reponse2, etc , both of these variables will give Hello , World  respectively .
In the Ajax Usage 1, Ajax is unaware that the data in response in Ajax so we manually have to decode and parse that response data to use the variables in it. This usage is used for both the condition when you are getting JSON as response  or you are getting a normal response other then JSON  To use the response data which is not in a JSON form then just remove the line with jQuery.parseJSON(data) and directly use the response data.


In Ajax Usage 2, we have used dataType:"json" in the Ajax settings before sending the data through Ajax in place of parsed_data = jQuery.parseJSON(data) in the response function of ajax. In this we are prior telling the Ajax that the data that will we received will be just in the JSON form and not in any other form. So, Ajax here automatically parse that JSON encoded data of the form as shown above and to use the variables in this data response you can use the same syntax as defined above like data.response1 , data.reponse2,etc. This usage is used where the response data which is received is just of the JSON form. If here you try to use the data directly not of the JSON form, you will get nothing in data. 


Hope you like this post……..Please Comment…………!!!!!!!!!


Saturday, November 23, 2013

Easy jQuery Dropdown Menu with attractive CSS

Saturday, November 23, 2013 - 0 Comments

Hiiii, nowadays many dropdown menus are available in market which you can implement on your website but sometimes they are not easy to implement and sometimes managing CSS for that dropdown are so difficult. One major thing more that you will find very less websites on internet without a dropdown menu. Dropdown allows you to manage the links on you website in a very attractive way and in a very organized way. So here in this post , I will be telling you how to implement an  attractive Dropdown in a very easy way with a feature of giving links to all the menu items. 

DROPDOWN MENU DEMO VIEW :


DROPDOWN MENU CODE BEGINS :

<html> <head> <title>Simple Dropdown</title> <script src="http://code.jquery.com/jquery.js"></script> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> </head> <body> <div style="width:50%; height:30%; border:2px solid #DDDDDD; margin-left:20px; margin-top:20px;"> <h1>&nbsp;Simple Dropdown Tutorial</h1> <div class="bs-example" style="margin-left:10px;"> <ul class="nav nav-pills"> <li class="active"><a href="#">Home</a></li> <li class="dropdown"> <a href="#" data-toggle="dropdown" role="button" id="drop4">Dropdown <b class="caret"></b></a> <ul aria-labelledby="drop4" role="menu" class="dropdown-menu" id="menu1"> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Action</a></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Another action</a></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Something else here</a></li> <li class="divider" role="presentation"></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Separated link</a></li> </ul> </li> <li class="dropdown"> <a href="#" data-toggle="dropdown" role="button" id="drop5">Dropdown 2 <b class="caret"></b></a> <ul aria-labelledby="drop5" role="menu" class="dropdown-menu" id="menu2"> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Action</a></li> <li class="divider" role="presentation"></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Separated link</a></li> </ul> </li> <li class="dropdown"> <a href="#" data-toggle="dropdown" role="button" id="drop6">Dropdown 3 <b class="caret"></b></a> <ul aria-labelledby="drop6" role="menu" class="dropdown-menu" id="menu3"> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Menu Item 1</a></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Menu Item 2</a></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Menu Item 3</a></li> <li class="divider" role="presentation"></li> <li role="presentation"><a href="https://twitter.com/Mycodesstock" tabindex="-1" role="menuitem">Menu Item 4</a></li> </ul> </li> </ul> <!-- /tabs --> </div> </div> </body> </html>

Hope you like this post……..Please Comment…………!!!!!!!!!

Wednesday, November 13, 2013

Easy jQuery Tabbing with attractive CSS

Wednesday, November 13, 2013 - 0 Comments

Hiiiii, being a developer many times it happens that we want to implement a tabbing system and want to display data in that tabs without page refresh. Some find it difficult to implement but here I am teaching you to implement it in a very easier view. Tabs gives a very beautiful looks to your site and also organize the data viewed on your site in a very organised manner. As jQuery is used then it is very fast and efficient without any refreshing of page. The tabbing I'll be teaching here will have good CSS and nice looks.


CODE BEGINS :

<html>
<head>
<title>Modal</title>
<script src="http://code.jquery.com/jquery.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</head>

<body>
<div style="width:50%; height:30%; border:2px solid #DDDDDD; margin-left:20px; margin-top:20px;">
<h1>&nbsp;Welcome to Tabbing Tutorial</h1>

<!-- Nav tabs -->
<ul class="nav nav-tabs">
 <li><a href="#home" data-toggle="tab">Home</a></li>
 <li><a href="#profile" data-toggle="tab">Profile</a></li>
 <li><a href="#messages" data-toggle="tab">Messages</a></li>
 <li><a href="#settings" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
 <div class="tab-pane active" id="home">
This is Home</br>
This is Home</br>
This is Home</br>
 </div>
 <div class="tab-pane" id="profile">
This is profile</br>
This is profile</br>
This is profile</br>
 </div>
 <div class="tab-pane" id="messages">
This is message</br>
This is message</br>
This is message</br>
 </div>
 <div class="tab-pane" id="settings">
This is settings</br>
This is settings</br>
This is settings</br>
 </div>
</div>
</div>
</body>
</html>


Hope you like this post……..Please Comment…………!!!!!!!!!

Tuesday, October 29, 2013

New Improved and Easy to Use jQuery Dialog (Modal) with CSS and Nice Functionality

Tuesday, October 29, 2013 - 1 Comment

Hiiiiiii, we all want our site to be attractive with sliders, carousel, popups, tooltips, dialogs etc. Most of you have used many effects and features as provided by jQuery UI. I also use these jQuery features many a times, but now I am bored with jQuery UI features and also I can across the fact that jQuery UI doesn't provide that much good CSS and and effects that many other JS in the markets provide. So, here in this post, I'll be telling you how to open a new type of Dialog with improved CSS and it is easy to use. Here in this tutorial, dialog is referred as 'Modal'. The Opened Modal will look like as shown below :

Bootstrap JS Modal


CODE BEGINS :

<html>
<head>
<title>Modal</title>
<script src="http://code.jquery.com/jquery.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</head>

<body>
<h1> Welcome to Modal/ Dialogue open Tutorial<h2>
<!-- Button to trigger modal/dialogue -->
  &nbsp;<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Open Modal</a>

  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Modal title</h4>
        </div>
        <div class="modal-body">
         This is you Modal Body.
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save</button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
</body>
</html>


Hope you like this post……..Please Comment…………!!!!!!!!!

Friday, October 18, 2013

Implementing Google Maps On Your Site

Friday, October 18, 2013 - 0 Comments

Hiiii, we all know that Google maps is powerful application which allows to get location information with actual coordinates value. You may have seen Google maps on some website demanding for you location and it calculates the coordinates correspondingly according to your location. So, here in this tutorial, I will be teaching you how to integrate Google maps on your website.

Google Maps

In these maps, coordinates values are automatically fetch when the user puts marker on the map. This tutorial which I will be teaching here will have Google map, putting,hiding and deleting markers on the map functionality.
It is very light weight Google Maps code and easy to use and it is mostly build in javascript.
 

CODE BEGINS :

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
var myCenter=new google.maps.LatLng(51.508742,-0.120850);
var markers = [];
var map;
function initialize()
{
var mapProp = {
center:myCenter,
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map,
});
markers.push(marker);
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
}
}
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
function clearMarkers() {
setAllMap(null);
}
function showMarkers() {
setAllMap(map);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<input onclick="clearMarkers();" type=button value="Hide Markers">
<input onclick="showMarkers();" type=button value="Show All Markers">
<input onclick="deleteMarkers();" type=button value="Delete Markers">
<div id="googleMap" style="width:700px;height:400px;"></div>
</body>
</html>

Hope you like this post……..Please Comment…………!!!!!!!!!

Wednesday, October 9, 2013

How to Include Custom Javascript in Wordpress (wp_enqueue_scripts)

Wednesday, October 9, 2013 - 0 Comments

Hiiii, those who uses wordpress for web developent must be knowing this and those who are new to wordpress. to them I want to tell tell that you can't just use our javascript code in wordpress same as we use in core PHP.
In wordpress all the '$' in jQuery code must me replaced with 'jQuery' and you don't have to include "jQuery js" beacause wordpress itself provides a support for jQuery.
In wordpress , you can't use the javascript code written by you anywhere in rest of your code rather after writing your code anywhere in you website, you have to send that javascript code to wordpress site 'header'.
To perform this function of sending and including a custom javascript code in wordpress , a function namely- wp enqueue script is used. So. in this post I wiil telling how to use wp enqueue script function to make your javascript code work in wordpress.



CODE BEGINS :

<?php
function my_scripts_method() {
wp_enqueue_script(
'jquery.flexslider',
plugins_url() . '/webauctioneers_banner/js/jquery.flexslider.js',
array( 'jquery' )
);
wp_enqueue_script(
'webauctioneers',
plugins_url() . '/webauctioneers_banner/js/webauctioneers.js',
array( 'jquery' )
);
wp_enqueue_script(
'shCore',
plugins_url() . '/webauctioneers_banner/js/shCore.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
?>

Hope you like this post……..Please Comment…………!!!!!!!!!

Tuesday, October 8, 2013

Shake the Form on Wrong Username and Password

Tuesday, October 8, 2013 - 0 Comments

Hiiii, it always looks great if you put many animations or effects on your site and even visitor gets a good impression about your site and for a developer too.
Approximately all of you had developed many login system and even you have worked on many CMS like Wordpress,Joomla and Drupal. Those who have worked on Wordpress must have seen the shaking of login form for Admin section when you enter a wrong username or password.
That shaing of form looks attarctive rather than simple Login form.
So, here in this post I'll be teaching you how to shake the login form or any other form of your choice on some wrongly entered data fields like wrong username or password, etc.

Shake the Form


CODE BEGINS :


effect.php

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mycodestock</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
.toggler { width: 500px; height: 200px; position: relative; }
#button { padding: .5em 1em; text-decoration: none; }
#form_div { width: 240px; height: 160px; padding: 0.4em; position: relative; }
#form_div h3 { margin: 0; padding: 0.4em; text-align: center; }
.ui-effects-transfer { border: 2px dotted gray; }
body {
font-size: 62.5%;
font-family: "Trebuchet MS", "Arial", "Helvetica", "Verdana", "sans-serif";
}
</style>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#myform").validate({
rules: {
username: "required",
password: {
required: true,
},
},
messages: {
username: "Please specify your name",
password: "Enter The password",
},
submitHandler: function()
{
var senddata=$("#myform").serialize();
$.ajax({
url: 'post.php',
data:senddata,
type:'POST',
success: function(data,textStatus){
var vdata = jQuery.parseJSON(data);
if(vdata.error)
{
function runEffect() {
var selectedEffect = $( "#effectTypes" ).val();  // get effect type from
$( "#form_div" ).effect( selectedEffect, 500, callback );    // run the effect
};
function callback() {        // callback function to bring a hidden box back
setTimeout(function() {
$( "#form_div" ).removeAttr( "style" );
}, 1000 );
};
$("#error_label").html('<strong>'+vdata.message+'</strong>');
runEffect();
return false;
}
else
{
$("#error_label").html('<strong>'+vdata.message+'</strong>');
}
}
});
}
});
});
</script>
</head>
<body>
<div align="center" >
<div>
<div id="form_div">
<h3>Form</h3>
<p id="error_label"></p>
</br>
<form id="myform">
<input type="text" name="username" placeholder="Username">
<input type="text" name="password" placeholder="Password">
</br>
<!--input type="submit" id="button" value="Submit"-->
<input type="hidden" value="shake" id="effectTypes">
<input type="submit" value="submit">
</form>
</div>
</div>
</div>
</body>
</html>

post.php :

<?php
if($_POST)
{
if($_POST['username']=="admin")
{
if($_POST['password']=="admin")
{
echo '{"error":"","message":"You are logged in"}';
}
else
{
echo '{"error":"password_wrong","message":"Password mismatch"}';
}
}
else
{
echo '{"error":"username_wrong","message":"username mismatch"}';
}
}
?>

Put both of the above files in a same folder and run.

Hope you like this post……..Please Comment…………!!!!!!!!!

Monday, October 7, 2013

Sending Form Data to Next Page using JQUERY

Monday, October 7, 2013 - 1 Comment

Hiiii, sometimes we need to submit a form on our website and also wants that page does not gets refresh on form submit (which is a popular trend nowadays). But this no refreshing thing can only be possible by Javascript.
So, in this post I'll be teaching you how to submit a form using jQquery and send the data of form to a next page using ajax in a very simple manner.
You can also add validation within this code before form gets submit and is the form is filled correct then call the form's submit function.

Sending Form Data to Next Page using JQUERY

Here's the code :

<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
$('#saveattribute').click(function(){

//you custom code but here I am sending values to next page
jQuery.ajax({
type: "POST",
url: "abcd.php",
data: $('#attribute_save').serialize()
}).done(function( msg ) {
//alert(msg);
//your code on success
});
})
})
</script>
</head>
<body>
<form id="attribute_save">
<table>
<tr>
<td>Select Style:
<select name="style_att" id="Attr">
<option value="">Select..</option>
<option value="23">men</option>
<option value="53">ringer-t</option>
<option value="52">t-shirt</option>
</select>
</td>
<td><input type="button" id="saveattribute"  value="Save"/></td>
</tr>
</table>
</form>
</body>
</html>

Hope you like this post……..Please Comment…………!!!!!!!!!

Saturday, October 5, 2013

jQuery Validation Plugin

Saturday, October 5, 2013 - 0 Comments

Hiiiii, we all know that every form developed on any website or project is incomplete without the validations on it. Form validations restricts the form to be submitted  without filling fields or filling the fields like email or phone no with some wrong or irrelevant values with wrong syntax. These validations are applied through javascript. Earlier the validations code was lengthy but now jQuery website has launched a Validation Plugin to validate a form in a very simple manner. So, in this post I will be teaching you how to use this JQuery Validation plugin with a simple example.

jQuery Validation Plugin

CODE BEGINS :

<html>
<head>
<!–script src="js/jquery-1.9.1.min.js"></script–>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#myform").validate({
rules: {
username: "required",
email: {
required: true,
email: true
},
comment:"required",
date_from: {
required: true,
date: true
},
},
messages: {
username: "Please specify your name",
email: {
required: "We need your email address to contact you",
email: "Your email address must be in the format of name@domain.com"
},
comment: "Enter The comment",
date_from: {
required: "enter the date from"
},
},
submitHandler: function()
{
$( "#myform" ).submit();
}
});
});
</script>
</head>
<body>
<form id="myform" method="POST" action="">
Name :</br>
<input type="text" name="username"></br>
Comment :</br>
<textarea name="comment" style="width: 235px; height: 70px; overflow:true; resize:false;"></textarea></br>
Date From :</br>
<input type="text" name="date_from" id="date_from"></br>
Email ID :</br>
<input type="text" name="email"></br>
<input type="submit" value="submit">
</form>
</body>
</html>
<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>

Hope you like this post……..Please Comment…………!!!!!!!!!

Saturday, September 28, 2013

JQUERY CODE TO PERFORM FUNCTION ON SELECTING SELECT BOX OPTIONS

Saturday, September 28, 2013 - 0 Comments

Hiiii, Sometimes it is necessary to get an ID of the selected select box options and then perform some function on that selected ID. So, here is the code to perform some work on the options selected for some select box with the help of JQuery. It  means that you don’t have to submit that form but function performs on just select.
JQUERY FUNCTION ON SELECTING SELECT BOX OPTIONS

So here is the simple and short JQuery code to do so:

jQuery(document).ready(function(){
jQuery( “#Attr” ).change(function () {             //#Attr is the id of the select box
var id = jQuery(this).val();
//alert(id);
var request_type=”get_desc”;
jQuery.ajax({
type: “POST”,
url: “abcd.php”,              //abcd.php is the file name to which data is to be sent
data: {req_type:request_type,attr_id:id}
}).done(function( msg ) {
//alert(msg);
jQuery(“#attribute_description”).val(msg);
});
});
})
The above code sends the data (value of option selected, etc) on “abcd.php” on the change of select box (with ID : Attr) options and receive a data back in “msg” variable , whose value is then inserted into a text area with ID : attribute_description.

Hope you like this post……..Please Comment…………!!!!!!!!!

Originally posted at Mycodestock.

Friday, September 20, 2013

Simple JQuery Image Slider

Friday, September 20, 2013 - 0 Comments

Hiiii, all of you know that image sliders and some image effects makes the look of a site so attractive. So, Here is the code example to show how to slide images through JQuery. The tutorial shown is full customizable and you can set the images to view at once according to your convenience . In this tutorial I have shown just 5 sliding images .
Here is the image below to show how this slider looks :
Simple JQuery Image Slider

To download the complete set of files used in this tutorial,

CLICK HERE.

You will also be requiring some images to run this tutorial …so demo images are below and you van download it from here
 
 


Hope you like this post……..Please Comment....!!!!!!
Originally posted at Mycodestock.

Wednesday, September 18, 2013

IMAGES IN HTML SELECT OPTIONS (STAR RATING DEMO)

Wednesday, September 18, 2013 - 0 Comments

Here in this post I will give a tutorial about how to insert images in the select options in html . You cannot put images in select box by just specifying the path of the image in options…….For this you require some extra javacripts and css which i have provide in this tutorial ..
Here i have  created a star rating form with stars image in select box options as shown below :
IMAGES IN HTML SELECT OPTIONS (STAR RATING DEMO)

For this , you require files with complete Javascripts and CSS and to download all the files needed in this demo,

CLICK HERE

There only the code files on the link specified above …..but you need additional star images to complete this demo and you can download the images shown below :
1star

2star

3star

4star

5star

Download the above shown images row wise one by one by right clicking on it and selecting “Save image As…..”
Hope you like this post……..Please Comment....!!!!!!
Originally posted at Mycodestock.

Monday, September 16, 2013

Selecting chechboxes via Javascript

Monday, September 16, 2013 - 0 Comments

Hiiii, Sometimes it happens that we want to perform a same action like delete on many records of the table in html , so to do this we require a checkboxes to select records on which action is to be performed. So, In this post I'll give you the tutorial of how to select all the checkboxes by just selecting a header checkbox or by manually selecting checkboxes.
Selecting chechboxes via Javascript

Here's the code below :

Creating a Checkbox HTML :

<table id=”table_name”>
<thead>
<tr>
<th><input type=’checkbox’ id=”check_all”></th>
</tr>
</thead>
<tbody>
<tr> <td><input type=”checkbox” name=”ids[]” value=”some id like 1,2,etc”></td> </tr>
</tbody>
</table>

Javascript code to select all checkboxes :

$( document ).on(“click”, “#check_all”,function() {
var checkedStatus = this.checked;
$(‘#table_name tbody tr’).find(‘td:first :checkbox’).each(function () {
$(this).prop(‘checked’, checkedStatus);
});
});

Getting array of ids of checkboxes selected :

$( document ).on(“click”, “#button_id”,function() {
var ids_arr = [];
$(“[name='ids[]‘]:checked”).each(function() {
ids_arr.push(this.value);
});
});
This ids_arr array you are getting is the array of ids checked/ selected. You have to pass this array to the next page through ajax where function or database queries to do with the selected ids is written.

To see How to send data on next page or same page through Ajax , CLICK HERE

 

Hope you like this post……..Please Comment....!!!!!!
Originally posted at Mycodestock.

JQUERY response data (splitting to array and then access through Foreach)

Hiiii, JQuery itself comes with a tagline that "Write less, Do more". So this tutorial is all about JQuery and ajax data sending and receiving  and it also explains that sometimes we receive an array in ajax response which is bot encoded than how to split that array and use the values in that array .
JQUERY



So Here's the code for this tutorial :


To split a array use :

var array_data=data.split(” “);   //enter the character or space in (“”) around which you wanna split your aaray .

To access that data  use :


jQuery.each(array_data, function(index, value) {
alert(index + ‘: ‘ + value);
});

Complete example for reference :


jQuery(function(){
jQuery(“#comment_form”).show();
//jQuery(“#comment_submitted”).hide();
jQuery(“#do_comment”).submit(function(){
var senddata=$(“#do_comment”).serialize();
//alert(senddata);
jQuery.ajax({
url: urlll,
data:senddata,
type:’POST’,
success: function(data){
//    var response = jQuery.parseJSON(data);
var temp=0;
var array_data=data.split(” “);
//alert(array_data);
jQuery.each(array_data, function(index, value) {
if(value==”[http_code]“){
temp=index+2;
}
if(value==202 && temp==index){
//alert(index);
jQuery(“#comment_submitted”).html(“Comment Submitted”);
}
if(value==403 && temp==index){
jQuery(“#comment_submitted”).html(“Comment Already Posted”);
}
//alert(index + ‘: ‘ + value);
});
//alert(array_data.get(0));
jQuery(“#comment_form”).hide();
jQuery(“#comment_submitted”).show();
var cdata=data;
var array_data=cdata.split(” “);
}
});
return false;
})
});

Hope you like this post……..Please Comment…………!!!!!!!!!
Originally posted at Mycodestock

© 2013 MyCodeStock. All rights reserved.
Designed by SpicyTricks