Populate Select box dynamically by ajax in Cakephp

To populate a select box by cakephp ajax functionality.
Step 1.
In the end of your view (.ctp)file.This is your javascript code in cake.

<?php
$this->Js->get('#select1')->event('click', 
$this->Js->request(array('controller'=>'ControllerName','action'=>'ajax_call'), array(
'update'=>'#select2',
'async' => true,
'method' => 'post',
'dataExpression'=>true,
'data'=> $this->Js->serializeForm(array(
'isForm' => true,
'inline' => true))
))
);
?>

Step 2.
In your controller file create function with that returns options string

public $helpers = array('Js'); //load Js helper
public function getBySubject(){
	
		$this->autoRender=false; //prevent to load default layout
$option;		
//your code
		printf($option);
		}

step 3.
In the end or your layout file after your loaded scripts

<?php
if (class_exists('JsHelper') && method_exists($this->Js, 'writeBuffer')) echo $this->Js->writeBuffer();
// will write your cached scripts
?>
Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone
  

Detect Mousewheel events by jQuery

$(function () {
   var isChrome = !!window.chrome && !!window.chrome.webstore; //use to resolve browser compatibilty issue.
   var functionname="mousewheel.focal";
   if(!isChrome)
	functionname="DOMMouseScroll";
   $('Selector').bind(functionname, function{
	var delta = (isChrome) ? e.delta || e.originalEvent.wheelDelta : e.originalEvent.detail;
        if(isChrome && delta < 0){
	     //scroll down in chrome
	 }
        elseif(isChrome && delta > 0){
            //scroll up in chrome
	}
        elseif(!isChrome && delta > 0){
            //scroll down in mozilla
	}
        else{
            //scroll up in mozilla
	}
	return false;
    });
});

Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone
  

Show confirm box before mailto function

<a href="mailto:info@codeexecute.com" onclick="return confirm('do you want to continue');">Click Me</a>

or 

<a href="mailto:info@codeexecute.com">Click Me</a>
<script>
jQuery(document).ready(function(){
	jQuery('a[href^="mailto"]').click(function(){
		return confirm('do you want to continue');
	});
});
</script>
Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone
  

Insert form details to database and then redirect to Paypal using javascript in php

<!--insert into database-->
<?php 
if(isset($_POST['submit'])){
$email=$_POST['email'];
$amount=$_POST['amount'];
$sql = "INSERT INTO payment(emailid , pay_amount) VALUES('".$email."','".$amount."')"; 
$result=$mysqli_query($conn, $sql);
}
?>

<!--form-->
<form method="post" action="">
<input type="email" name="email">
<input type="text" name="amount">
<button name="submit">Pay</button>
<?form>

<!--paypal form-->
<form id="paypal_submit_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr"  method="post">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="yourbusinessid@b.com">
<input type="hidden" name="item_name" value="Donation">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="action" value="formaction">
<input type="hidden" name="email" id="emailid"  value="<?php echo $_POST['email'];?>" >
<input type="hidden" id="amountid" name="amount"  value="<?php echo $_POST['amount'];?>" >
</form>

<!--Javascript-->
<script type="text/javascript">
document.getElementById("paypal_submit_form").submit();
</script>
Share on Google+Share on FacebookTweet about this on TwitterEmail this to someone
  
Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.