Javascript Archives | Page 2 of 4 | Codeexecute

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;
    });
});

 
 
 

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>
 

Grouping of select box options through javascript

Your select box 

<select>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
<option value="ddd">ddd</option>
<option value="eee">eee</option>
<option value="fff">fff</option>
</select>
<script type="text/javascript">
$(function () {
    var $cont = $('select');
   
    $('select option').each(function () {
        if ($(this).text().indexOf('aaa') === 0 || $(this).text().indexOf('ddd') === 0) {
            $('<optGroup/>').attr('label', $(this).text()).appendTo($cont);
            $(this).remove();
        } else {
            $cont.find('optGroup').last().append($(this));
            $(this).text($(this).text());
        }
    });
    });

</script>