Wednesday, June 24, 2015

submit form with form.serialise and parse the data into php

JS Things


function submitData(){
var dataString = $('form').serialize(); // your data will serialize
console.log("check data-: \n \t "+dataString);
$.ajax({
type:'POST',
url: "path/to/file.php",
data:{'validateMe':dataString}
}).done(function(msg) {
console.log(msg);
}).fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus_jqXHR );
 });
return false;
}


-------------------------------

PHP  Things

<?php
if(isset($_REQUEST['validateMe']))

$data=$_REQUEST['validateMe'];
parse_str($_REQUEST['validateMe'],$data);

echo '</pre>';
print_r($_REQUEST['data']);
print_r($_data); // this is your formatted Data.
echo '</pre>';
?>

Use the JavaScript width() method

You can set the width of a <div> box dynamically using the jQuery width() method.
The width() method simply returns the element's width as unit-less pixel value. However calling the width(value) method sets the width of the element, where the value can be either a string (e.g. 100%50px25emauto etc.) or a number. If only a number is provided for the value, jQuery assumes it as a pixel unit.


Copy Code Below

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Set a DIV width</title>
<style type="text/css">
    .box{
        float: left;
        background: #f2f2f2;
        border: 1px solid #ccc;
    }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".set-width-btn").click(function(){
        var newWidth = $(".input-width").val();
        $(".box").width(newWidth);
    });
});
</script>
</head> 
<body>
    <form>
        <input type="text" class="input-width">
        <button type="button" class="set-width-btn">Set Width</button>
        <p>Enter the value in input box either as number (e.g. 100, 200) or combination of number and unit (e.g. 100%, 200px, 50em, auto) and click the "Set Width" button.</p>
    </form>
    <br>
    <div class="box">This is simple DIV box</div>
</body>
</html>

How to bind click event if HTML elements added dynamically in jQuery

If you try to do something with the elements that are dynamically added to DOM using the jQuery click() method it will not work, because it bind the click event only to the elements that exist at the time of binding. To bind the click event to all existing and future elements, use the jQuery on() method. Check out the following example.



Copy Code Below

<html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Bind onclick Event to Dynamically added Elements</title> <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("ol").append("<li>list item <a href='javascript:void(0);' class='remove'>&times;</a></li>"); }); $(document).on("click", "a.remove" , function() { $(this).parent().remove(); }); }); </script> </head> <body> <button>Add new list item</button> <p>Click the above button to dynamically add new list items. You can remove it later.</p> <ol> <li>list item</li> <li>list item</li> <li>list item</li> </ol> </body> </html>

Mysql Query to toggle int value


Hey.. want to toggle a field value from 0 to 1 or 1 to 0 in single query..

There are Several Method



UPDATE `tbl1` SET clmn = clmn XOR 1

UPDATE `tbl1` SET clmn = 1 - clmn



UPDATE tbl1   SET `status` = !`status`






Advertisement

Tuesday, June 23, 2015

Pagination with Jquery and PHP

<?php
$pageNumber=$_REQUEST['page'];
$pageFrom=($pageNumber==1?0:($p_value*10-10));
$pageLimit=($pageNumber==1?10:($p_value*10+10));

$data=array_slice($all_data, $pageFrom, $pageLimit );
 foreach($data as $key => $value){

    // your code goes here..
}

?>

Note-: Your all row should be save in array. this code will just slice all record into 10-10 pieces..


Want more help-: contact me on facebook.com/sudhir600