Javascript Archives | Page 2 of 4 | Codeexecute

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.

$this->Js->request(array('controller'=>'ControllerName','action'=>'ajax_call'), array(
'async' => true,
'method' => 'post',
'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
//your code

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

if (class_exists('JsHelper') && method_exists($this->Js, 'writeBuffer')) echo $this->Js->writeBuffer();
// will write your cached scripts

Detect Mousewheel events by jQuery

$(function () {
   var isChrome = !! && !!; //use to resolve browser compatibilty issue.
   var functionname="mousewheel.focal";
   $('Selector').bind(functionname, function{
	var delta = (isChrome) ? || 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
            //scroll up in mozilla
	return false;


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

<!--insert into database-->
$sql = "INSERT INTO payment(emailid , pay_amount) VALUES('".$email."','".$amount."')"; 
$result=$mysqli_query($conn, $sql);

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

<!--paypal form-->
<form id="paypal_submit_form" action=""  method="post">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="">
<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'];?>" >

<script type="text/javascript">