Showing posts with label Jquery Validate URL. Show all posts
Showing posts with label Jquery Validate URL. Show all posts

Wednesday, 3 June 2015

Calling php functions by jquery Calling php functions by using jquery Ajax

<?php 

/*
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
 if(!radioObj)
  return "";
 var radioLength = radioObj.length;
 if(radioLength == undefined)
  if(radioObj.checked)
   return radioObj.value;
  else
   return "";
 for(var i = 0; i < radioLength; i++) {
  if(radioObj[i].checked) {
   return radioObj[i].value;
  }
 }
 return "";
}
// radio button example
//<input name="mail_type" id="mail_type" type="radio" value="plain" <?php echo (isset($mail_type) && $mail_type == 'plain') ? 'checked="checked"' : '' ; ?> onclick="javascript:change_content_area(this.value);"/>

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
 if(!radioObj)
  return;
 var radioLength = radioObj.length;
 if(radioLength == undefined) {
  radioObj.checked = (radioObj.value == newValue.toString());
  return;
 }
 for(var i = 0; i < radioLength; i++) {
  radioObj[i].checked = false;
  if(radioObj[i].value == newValue.toString()) {
   radioObj[i].checked = true;
  }
 }
}
// checkbox example
//<input type="checkbox" id=cb'.$i.' name="cid[]" value="'.$val['id'].'" onclick="javascript:isChecked(this.checked);" />





// Function returns true if one radio button is checked from a group else returns false;
function get_check_box_value(check_box_name) {
 var r = '';
 var checkbox = document.getElementsByName(check_box_name);
 for (var i=0; i < checkbox.length; i++)
    {
     if (checkbox[i].checked)
       {
       var r = checkbox[i].value;
       }
    }

 if(r != '') {
  return true;
 }
 else {
  return false;
 }
}


// function to validate url
// valid url - http://www.mysite.com
//       https://abc.mysite.com
//    http://abc.mysite.co.in
//    http://abc.mysite.com/index.php
//    http://abc.mysite.com/index.php?action=do
function validate_url(url) {

    var RegExp = /^(ftp|https?):(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;

    if(RegExp.test(url)) {
  // alert('\''+url+'\''+' is a valid URL, Thanks.');
        return true;
    } else {
  alert('\''+url+'\''+' is not a valid URL.');
        return false;
    }
}


// Function returns true if checkbox is checked else false
function validate_chkbox(chkbox_name) {
 return document.getElementById(chkbox_name).checked;
}


// Function to validate credit card numbers
function isValidCreditCard(type, ccnum) {
   // VISA
   if (type == "5") {  
      // Visa: length 16, prefix 4, dashes optional.
      var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
   // MASTER CARD
   } else if (type == "4") {  
      // Mastercard: length 16, prefix 51-55, dashes optional.
      var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
   // DISCOVER
   } else if (type == "3") {
      // Discover: length 16, prefix 6011, dashes optional.
      var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
   // AMERICAN EXPRESS
   } else if (type == "6") {
      // American Express: length 15, prefix 34 or 37.
      var re = /^3[4,7]\d{13}$/;
   // DINNERS CLUB
   } else if (type == "2") {
      // Diners: length 14, prefix 30, 36, or 38.
      var re = /^3[0,6,8]\d{12}$/;
   }
   if (!re.test(ccnum)) return false;
   // Remove all dashes for the checksum checks to eliminate negative numbers
   ccnum = ccnum.split("-").join("");
   // Checksum ("Mod 10")
   // Add even digits in even length strings or odd digits in odd length strings.
   var checksum = 0;
   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
      checksum += parseInt(ccnum.charAt(i-1));
   }
   // Analyze odd digits in even length strings or even digits in odd length strings.
   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
      var digit = parseInt(ccnum.charAt(i-1)) * 2;
      if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
   }
   if ((checksum % 10) == 0){ 
    //alert('TRUE');
    return true; 
   }else{
    //alert('FALSE');
    return false;
   }
}

// validate email address
function validate_email(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
 {
   return true;
 }
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
     var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
     if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}


// #########################################################
// #########################################################
// JQUERY FUNCTIONS STARTS
// #########################################################
// #########################################################

// Note : Replace '$' with jQuery if it conflicts
// and add " jQuery.noConflict(); "

//<a id="ppsub_ppterm_id"> = $("#ppsub_ppterm_id")

//<a class="ppsub_ppterm_id"> = $(".ppsub_ppterm_id")

//<a name="ppsub_ppterm_id">  = $("*[name=ppsub_ppterm_id]")

// function view_intro(divid) { 
// var c = "#"+divid; 
// $(c).html('Hello');
// }

// This function returns value of checkbox if checkbox is checked else 0;
function get_chkbox_value(chkbox_name) {
 var chkbox = $("input:checkbox[name="+chkbox_name+"]");
 var rs = chkbox.attr("checked") ? chkbox.val() : 0;
 return rs;
}
// OR
function get_chkbox_value2(chkbox_id) {
 var news=$(chkbox_id).is(':checked');
}
// OR
// <input type="checkbox" id=cb name="cid[]" value="'.$row->id.'" />
// <form action="seekers" name="f1" method="post" onsubmit="return check_checked_rows('cb');">
function check_checked_rows(checkboxName) {
 var flagText = false;
 $("input[@id='" + checkboxName + "']:checked").each(
  function(){
   if(this.checked == true){
    if( this.value != ''){
     //alert(this.value);
     flagText = true;
    }
   }
  }    
 );

 if(flagText == false) {
  alert('Please check atleast one row.');
  return false;
 }
 else {
  return true;
 }
}



// This function returns an array which contains values of check checkboxes
function get_all_checked_values() {
 var chkboxes = $("input:checkbox:checked");
}


// Sample ajax function
function showstaticpage(myurl){

 $('#static2').show();

 $.ajax({
  url :myurl,
  type: 'post',
  success: function(data, status) {
   alert(data);
   $("#staticpage2").html(data);
  },
  error: function (data, status, e)
  {
  alert(status);
  alert(e);
  }
    });
}


// Sample load function
function load(param) {
 $("#staticpage").load( "/staticpage",
  {url:param},
  function(data) {}
 );
}


// sample function to change the css class in jquery
function change_css_class(my_css_class) {
 $('#eventheader').addClass(my_css_class);
 $('#eventheader').attr("class");
 $('#eventheader').removeClass(my_css_class);
}


// Sample function to Populate state name on change of country
function populate_city() {

 $("#ppsub_ppterm_id").change(function(){
     var term = this.options[this.selectedIndex].text;

     if(term == "Eenmalig"){
       $(".idealtd").show();   
     }else{
       $(".idealtd").hide();   
       //$("#ppsub_amount option:selected").val('anders');
     }
 });
}

// show & hide div slowly
function change_category() {
 $('#div-change-category').show('slow');
 $('#div-change-category').hide('slow');

 // css used
 
 //.news-box-search
 //{
 //margin:0; padding:0; float:right; width:390px; position:relative; margin-bottom:-260px; z-index:5; font:normal 10px "Myriad Pro" Arial, Helvetica, sans-serif; color:#9d9c9c;
 //}

 //.overlap{ position:absolute; background:#e0e0e0; padding:8px; margin-top:35px; margin-left:115px; border:#ccc 3px solid;}
 

 // html div used
 
 //<div class="news-box-search overlap" id="div-change-category" style="display:none;">

   //<div style="float:right;"><a href="javascript:void(0);" onclick="return close_change_category();"><img src="/images/icon-close.gif" alt="" /></a></div>
   //<label>Change Category :</label>

  //<select name="categories" id="categories">
  //<option value="1">Music</option>
  //<option value="2">Literature</option>
  //<option value="3">Visual Arts</option>    
  //</select>

  //<input type="button" name="btn_change_category" id="btn_change_category" value="Change" onclick="return change_category2();" />
    //</div>
}

// ## Getting values from html element through jquery
function get_elements_value() 
{
 // getting drop down value
 // Drop down
 // <select name="posted_year">
 // <option value="">None</option>
 // <option value="2009">2009</option>
 // <option value="2008">2008</option>
 // </select>
 var cat = $('#posted_year').val();
}

// redirect url
function redirect_url(url)
{
 window.location=url;
}

// window onload function
function onready()
{
 $(document).ready(function() {
  var mail_type = '<?php echo $mail_type; ?>';
  change_content_area(mail_type);
  
 });
}
*/
?>