Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Friday, 18 May 2018

Multple checkbox selected or not

<script type="text/javascript" src='jquery.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$('#extend_auto_expired').click(function(){
$("input[type=checkbox]:checked").each(function() {
alert( $(this).val() );
});
});
});
</script>
<center>
<form name='ck'>
<?php
for($r=0; $r<10;$r++){
echo "<input type='checkbox' name='t[]' value='$r'>$r<br>";
}
?>
<input type="button" id="extend_auto_expired" value="Extend auto expired" class="buttongreen" name="Submit">
</form>
<center>

Saturday, 16 December 2017

Jquery get element each method


$( "li" ).each(function( index ) { console.log( index + ": " + $( this ).text() ); });

Jquery allow decimal & integer script



$(document).ready(function(){
  $(".notallowdec").keypress(function (e){
      if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57) ) {
            return false;
        }else{
    
    }
    });
  $('.allowdec').keypress(function(event){
    if ((event.which != 46 || $(this).val().indexOf('.') != -1)&&
(event.which < 48 || event.which > 57))
    {
    if((event.which != 46 || $(this).val().indexOf('.') != -1))
    {
      //alert('Multiple Decimals are not allowed');
    }
    event.preventDefault();
    }
    if(this.value.indexOf(".")>-1 && (this.value.split('.')[1].length > 1))
    {
    //alert('Two numbers only allowed after decimal point');
    //event.preventDefault();
    }
  });
  
});

Wednesday, 5 November 2014

How to disable Ctrl+V (Paste) , Ctrl+X (Cut) and Ctrl+C (Copy) with jQuery?

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
 $(document).ready(function(){
      $('#read').bind("cut copy paste",function(e) {
   e.preventDefault();
   alert(" 'Ctrl+c & Ctrl+x & Ctrl+v has been disabled' ")
      });
   });
});
</script>
<input type="text" id="read" />

How to disable right click in mouse event in jquery?

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
 $(document).bind('contextmenu', function (e) {
  e.preventDefault();
  alert('Right Click is not allowed');
 });
});
</script>

Friday, 24 October 2014

How to get the number of rows in a table - tbodyin jquery?

<table id="myTable" cellpadding="0" cellspacing="0">
  <thead>
    <tr>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Birth Date</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>John</td>
      <td>Smith</td>
      <td>03-11-1980</td>
    </tr>
  </tbody>
</table>

Solution:
$("#myTable tbody tr").length - Its wrong.
$("#myTable > tbody > tr").length; - Its right to get solution.

Friday, 10 October 2014

Autocomplete JQuery script full source code example

<script src="http://www.jqueryautocomplete.com/js/jquery/jquery-1.7.1.min.js"></script>
<script src="http://www.jqueryautocomplete.com/js/jquery/jquery.ui.core.min.js"></script>
<script src="http://www.jqueryautocomplete.com/js/jquery/jquery.ui.widget.min.js"></script>
<script src="http://www.jqueryautocomplete.com/js/jquery/jquery.ui.position.min.js"></script>
<script src="http://www.jqueryautocomplete.com/js/jquery/jquery.ui.autocomplete.min.js"></script>
<link rel="stylesheet" href="http://www.jqueryautocomplete.com/js/jquery/smoothness/jquery-ui-1.8.16.custom.css"/>
<script>var data = [
  {"label" : "Aragorn"},
  {"label" : "Arwen"},
  {"label" : "Bilbo Baggins"},
  {"label" : "Boromir"},
  {"label" : "Frodo Baggins"},
  {"label" : "Gandalf"},
  {"label" : "Gimli"},
  {"label" : "Gollum"},
  {"label" : "Legolas"},
  {"label" : "Meriadoc Merry Brandybuck"},
  {"label" : "Peregrin Pippin Took"},
  {"label" : "Samwise Gamgee"}
  ];
</script>
<script>
$(function() {

 $( "#search" ).autocomplete(
 {
   source:data
 })
});
</script>

<input type="text" id="search" />

Thursday, 9 October 2014

Enter Floating Number only

Input field onkeyup check floating values only to allow
onkeyup="if (!isFinite(this.value)) this.value = this.value.replace(/(\s+)?.$/,'')"

Saturday, 4 October 2014

Wednesday, 1 October 2014

Easy to integrate Facebook login to your web application

<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<span id="status"></span>
<script type='text/javascript'>
function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    console.log(response);
    if (response.status === 'connected') {
      testAPI();
    } else if (response.status === 'not_authorized') {
      document.getElementById('status').innerHTML = 'Please log ' +'into this app.';
    } else {
      document.getElementById('status').innerHTML = 'Please log ' +'into Facebook.';
    }
}
function checkLoginState() {
    FB.getLoginStatus(function(response) {  statusChangeCallback(response); });
}

window.fbAsyncInit = function() {
    FB.init({
        appId      : "FB_APP_ID", 
        cookie     : true,  // enable cookies to allow the server to access // the session
        xfbml      : true,  // parse social plugins on this page
        version    : 'v2.1' // use version 2.1
    });
    //FB.getLoginStatus(function(response) {  statusChangeCallback(response); });
};

(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
        console.log('Successful login for: ' + response.name);
        var name = response.name;
        var email = response.email;
        document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response.email + '!';
    });
}
</script>

Friday, 26 September 2014

Push method for javascript array

JavaScript Array pop() Method
var actors = ["Rajini", "Kamal", "Ajith", "Vijay"];
actors.push("Surya");
The result of fruits will be:
Rajini,Kamal,Ajith,Vijay,Surya

To remove array Last index value Javascript

JavaScript Array pop() Method
var actors = ["Rajini", "Kamal", "Ajith", "Vijay"];
actors.pop();
The result of fruits will be:
Rajini,Kamal,Ajith

Thursday, 25 September 2014

How to add segment insertAfter specific id in jQuery?

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("<p id=3>Hello world!</p>").insertAfter("#1"); }); }); </script> </head> <body> <button>Insert span element after each p element</button> <p id="1">This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>

Google Translator plugin for Browsers in Js

<script type="text/javascript">function googleTranslateElementInit() {
  var elem = new google.translate.TranslateElement({
    pageLanguage: "ca", 
    layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL,
    autoDisplay: false,
    floatPosition: 0
  });
  elem.onTurnOffLanguageClick = function() {
    var event = document.createEvent("Event");
    event.initEvent("translateExt_disable_lang", true, true);
    document.body.dispatchEvent(event);
  };
  var style = document.createElement("style");
  style.appendChild( document.createTextNode( ".global_header { top: 40px !important; }" ) );
  document.getElementsByTagName( "head" )[ 0 ].appendChild( style );
  elem.showBanner(false);
}</script>

Tuesday, 23 September 2014

How to convert string to number or integer in js?

var str = "123";
alert(str+"---"+typeof(str));
str = Number(str);
alert(str+"---"+typeof(str));

How to find variable type in js & jquery?

var str = "string";
alert(typeof(str)); //output: string

Input field enter integer only in jQuery

$(document).ready(function () {
    //called when key is pressed in textbox
    $("#quantity").keypress(function (e) {
        //if the letter is not digit then display error and don't type anything
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            //display error message
            $("#errmsg").html("Digits Only").show().fadeOut("slow");
            return false;
        }
    });
});

Number :
<input type="text" name="quantity" id="quantity" /> <span id="errmsg"></span>

Wednesday, 17 September 2014

How to get checked values in checkbox in dynamically by using jquery and javascript?

var chkArray = [];
$(".chk:checked").each(function() {
 chkArray.push($(this).val());
});
var selected;
selected = chkArray.join(',') + ",";
if(selected.length > 1){
 alert("You have selected " + selected); 
}else{
 alert("Please at least one of the checkbox"); 
}

Friday, 12 September 2014

Tuesday, 2 September 2014

Clock running scripts in php with jquery

<div class="col-xs-12 col-sm-12 col-lg-12 cal">
      <p id='demo' class="text-center cal-container"></p> 
   </div>
                       </a>
                       <?php
   
   $current_timestamp = time();
  ?>
                       <script type='text/javascript'>
                        flag = true;
            timer = '';
            phpJavascriptClock();
            setInterval(function(){phpJavascriptClock();},1000);
 
            function phpJavascriptClock()
            {
               
                if ( flag ) {
                    timer = <?php echo $current_timestamp;?>*1000;
                }
                var d = new Date(timer);
                months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 
'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
 
                month_array = new Array('January', 'Febuary', 'March', 
'April', 'May', 'June', 'July', 'Augest', 'September', 'October', 
'November', 'December');
 
                currentYear = d.getFullYear();
                month = d.getMonth();
                var currentMonth = months[month];
                var currentMonth1 = month_array[month];
                var currentDate = d.getDate();
                currentDate = currentDate < 10 ? '0'+currentDate : currentDate;
 
                var hours = d.getHours();
                var minutes = d.getMinutes();
                var seconds = d.getSeconds();
 
                var ampm = hours >= 12 ? 'PM' : 'AM';
                hours = hours % 12;
                hours = hours ? hours : 12; // the hour ’0' should be ’12'
                minutes = minutes < 10 ? '0'+minutes : minutes;
                seconds = seconds < 10 ? '0'+seconds : seconds;
                var strTime = hours + ':' + minutes+ ':' + seconds + ' ' + ampm;
                document.getElementById("demo").innerHTML= currentMonth+' 
' + currentDate+' , ' + currentYear + ' ' + strTime ;
                flag = false;
                timer = timer + 1000;
            }
                       </script>