Ad Code

JavaScript/jQuery Functions


<script>
$(document).ready(function(){

    // onSelectSubmit get id & value
    $('.OnChangeM').change(function(){
        GID = $(this).attr('id'); //alert(GID);
        if($("select[id='"+GID+"'] option:selected").val() != '')
            $('#'+GID+'_txt').val($("select[id='"+GID+"'] option:selected").text());
            $('#form'+GID+'').submit();
    });
    
    // OnSelect get id & value
    $('.OnSelectM').change(function(){
        GID = $(this).attr('id'); //alert(GID);
        if($("select[id='"+GID+"'] option:selected").val() != '')
            $('#'+GID+'_txt').val($("select[id='"+GID+"'] option:selected").text());
    });
    
    // Select ids, values
    $("select").on("change", function(){
      var id = $(this).attr("id");
      var id_val = $(this).val();
      var id_txt = this.options[this.selectedIndex].text;
      $("#"+id+"_txt").val(id_txt);
      //alert(id+"---"+id_val+"---"+id_txt);
    })
    
    // Selects all ids, values
    $(".mselect").change(function(){
        var str_ids = str_vals = "";
        $("select option:selected").each(function(){
            str_ids += $(this).val() + ",";
            str_vals += $(this).text() + ",";
        });
        $(".mselect_ids").val(str_ids);
        $(".mselect_vals").val(str_vals);
    }).trigger("change");

    // Select all checkboxes
    $("#ckbCheckAll").click(function () {
        $(".checkBoxClass").prop('checked', $(this).prop('checked'));
    });
    
    //autocomplete to off for all date input
    $( document ).on( 'focus', '.dt', function(){
        $(this).attr( 'autocomplete', 'off' );
    });
    

    // Filter non-digits from input value.
    $('.numeric').keyup(function(e){
        if(/\D/g.test(this.value)){
            // Filter non-digits from input value.
            this.value = this.value.replace(/\D/g, '');
        }
    });
    

    // Filter single quote from input value.
    $('input[type="text"]').keyup(function(e){
        // Filter single quote from input value.
        this.value = this.value.replace( /[\'\"]/g, '');
    });
    

    // Filter single quote from textarea value.
    $('textarea').keyup(function(e){
        // Filter single quote from input value.
        this.value = this.value.replace( /[\'\"]/g, '');
    });
    

    // Allow only numeric values
    $(".allow_numeric").on("input", function(evt){ // Allow only numeric values
        var self = $(this);
        self.val(self.val().replace(/[^\d].+/, ""));
        if((evt.which < 48 || evt.which > 57)){
            evt.preventDefault();
        }
    });
    

    // Allow numeric values with decimal
    $(".allow_decimal").on("input", function(evt){ // Allow numeric values with decimal
        var self = $(this);
        self.val(self.val().replace(/[^0-9\.]/g, ''));
        if((evt.which != 46 || self.val().indexOf('.') != -1) && (evt.which < 48 || evt.which > 57)){
            evt.preventDefault();
        }
    });

});

 

// How to show a confirm message before delete?

function myConfirm(){
  var result = confirm("Want to delete?");
  if(result==true) {
   return true;
  }else{
   return false;
  }
}

<input onclick="return myConfirm();" type="submit" name="deleteYear" class="btn btn-danger" value="Delete">
</script>

<a href="delete_methode_link" onclick="return confirm('Are you sure you want to Remove?');">Remove</a>

 

function trim(str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}

// USE
var email = trim(document.getElementById('email').value);


function isEmail(str) {
   var pattern =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
   return pattern.test(str);
}
//USE
if(isEmail(email)){ ... }else{ ... }

Post a Comment

0 Comments