Posts

Showing posts from March, 2016

Getting value of HTML Checkbox from onclick/onchange events

Image
  <html><head> </head> <body>   <div style="display: none;" id="container">Check Box is Checked</div> <br><br> <label>     <input id="mycheckbox" onclick="myChange()" type="checkbox">     </label> <script>     function myChange(){     var temp = document.getElementById('mycheckbox');     document.getElementById('container').style.display = temp.checked ? 'block' : 'none'; };     </script> </body></html>

How to set auto 2 decimal number in input type=“text” in javascript

var zzz = parseFloat ( numb ). toFixed ( 2 )   &&   function updateCost () { var amount = parseFloat ( document . getElementById ( "amount" ). value ), delivery = parseFloat ( document . getElementById ( "delivery" ). value ), total = amount + delivery , fixedrate = total / 100 * 8.2 , grandtotal = fixedrate + total ; document . getElementById ( "total" ). innerHTML = total . toFixed ( 2 ); document . getElementById ( "amountdiv" ). innerHTML = amount . toFixed ( 2 ); document . getElementById ( "deliverydiv" ). innerHTML = delivery . toFixed ( 2 ); document . getElementById ( "grandtotal" ). innerHTML = grandtotal . toFixed ( 2 ); document . getElementById ( "fixedrate" ). innerHTML = fixedrate . toFixed ( 2 ); } $ ( function (){ document . getElementById ( "amount" ). onchange = document .

PHP Ajax Login Validation Tutorial

Image
This post explains you about php login with ajax. In this example, first of all we will validate the user details using ajax library and showing the appropriate result. If user enter correct detail (ie:- admin/admin in this example)we will be redirected to the “index.php” and if you will try to directly access “index.php” means without entering the user details you will redirected to “login.php”. Download Link    Demo Link Sample database design for table name contact. This table contains id (primary key), name and age. CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `uname` varchar(50) NOT NULL `password` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) dbConnect.inc.php Contains database connectivity code $mysql_db_hostname = "Host name"; $mysql_db_user = "UserName"; $mysql_db_password = "Password"; $mysql_db_database = "Database Name"; $con = mysql_connect($mysql_db_hostname, $mysql_db_user,

dismiss bootstrap modal using jquery

$ ( function () { $ ( '#modal' ). modal ( 'toggle' ); });

basic php mysql login script without page reload

insert.php <?php     define('HOST','localhost');     define('USERNAME', 'root');     define('PASSWORD','');     define('DB','mydba');     session_start();     $con = mysqli_connect(HOST,USERNAME,PASSWORD,DB);         $username = $_POST['username'];     $pass = $_POST['password'];         //$_SESSION["username"] = $username;                 //$sql = "select * from users where username='$username' && password='$pass'";         //if(mysqli_query($con, $sql)){         //echo 'success';         //echo "   username is " . $_SESSION["username"] . ".";     //}         $sql="SELECT * FROM users WHERE username='$username' and password='$pass'";     $result=mysqli_query($con, $sql);     $count=mysqli_num_rows($result);     if($count==1){     //session_register("username"

PHP Document Expired This document is no longer available

If the 'Back' button is pressed on the browser, I get the following error: Document Expired This document is no longer available .     Add this in the start of PHP codes : ini_set ( 'session.cache_limiter' , 'public' ); session_cache_limiter ( false );  

MySQL query based on user input

  To save from SQL injection attack, use: 1. $search_query = mysql_real_escape_string ( $_POST [ 'blahblah' ]); $query = "SELECT name, age FROM people WHERE uid = '" . $search_query . "' LIMIT 0 , 1" ;   2. $search_query = mysqli_real_escape_string($_POST['code']); $sql = "select * from user where code='$search_query'";

response body json raw errod data - Ajax wont accept json when array

Image
I have the following line of code: print json_encode($organization_modules); $organization_modules is an array that looks like this: When i print this array to the following Ajax: $.ajax({ type: 'POST', url: '/Module/findByCategory', dataType: 'json', data: { request: 'ajax', category_id: id }, success: function (data) { $('#module_content').html(''); $('#module_content').prepend('<div class="col-md-12"><a href="/Modules/index" class="btn btn-primary"><i class="fa fa-arrow-left"></i> Tilbage</a></div>'); if(data.length > 0) {}); Nothing happens However if i print the following instead: it works just fine? So does it have something to do with the null values or what is going on? Response body <br /> <font size='

rewrite url in htaccess file

# Turn on the rewrite engine Options +FollowSymlinks RewriteEngine on # Request routing RewriteRule ^([a-zA-Z0-9_-]+)/?$ categorysearch.php?c_category=$1 # Request routing RewriteRule ^([A-Za-z0-9_-]+)/?$ subcategorysearch.php?c_subcategory=$1

rewrite multiple urls in one htaccess

Image
http://tools.seomoves.org/rewriter/

php mysql json restful webservice display data based on id

db.php <?php $servername="localhost"; $username="root"; $password=""; $database="tg"; //create connection$ $conn=new mysqli($servername, $username, $password, $database); //check connection if ($conn->connect_error) {     die("connection failed: ".$conn->connect_error); } ?>   Display full list   <?php include 'includes/db.php'; $cat_query="select * from coachings"; $cat_result=$conn->query($cat_query); if ($cat_result->num_rows > 0) {         while($cat_row = $cat_result->fetch_assoc()) {                $cat_msg[]=array("name" => $cat_row['c_name'], "address" => $cat_row['c_address'], "city" => $cat_row['c_city'],"state" => $cat_row['c_state'], "country" => $cat_row['c_country'], "pincode" => $cat_row['c_pincode'], "category&