domingo, 2 de febrero de 2020

Display and hide HTML elements

JQUERY
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("input[name=btnPassport]").click(function () {
                if ($(this).val() == "Yes") {
                    $("#dvPassport").show();
                } else {
                    $("#dvPassport").hide();
                }
            });
        });
    </script>
    <span>Do you have Passport?</span>
    <input type="button" value="Yes" name="btnPassport" />
    <input type="button" value="No" name="btnPassport" />
    <hr />
    <div id="dvPassport" style="display: none">
        Passport Number:
        <input type="text" id="txtPassportNumber" />
    </div>
</body>
</html>

JAVASCRIPT


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <script type="text/javascript">
        function ShowHideDiv(btnPassport) {
            var dvPassport = document.getElementById("dvPassport");
            dvPassport.style.display = btnPassport.value == "Yes" ? "block" : "none";
        }
    </script>
    <span>Do you have Passport?</span>
    <input type="button" value="Yes" onclick="ShowHideDiv(this)" />
    <input type="button" value="No" onclick="ShowHideDiv(this)" />
    <hr />
    <div id="dvPassport" style="display: none">
        Passport Number:
        <input type="text" id="txtPassportNumber" />
    </div>
</body>
</html>

lunes, 6 de enero de 2020

json array object

<?php


$data=array(array("name"=>"Ambiorix","Lastname"=>"Rodriguez","age"=>21));


$info=json_encode($data);

print_r("{info : ".$info."}");

?>

MYSQL to json Object array

<?php
$link = mysqli_connect("localhost", "root", "", "asteriskcdrdb");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$cars=array();

$query = " select * from  cdr limit 5";

if ($result = mysqli_query($link, $query)) {

    /* fetch associative array */
    while ($row = mysqli_fetch_assoc($result)) {
        echo "$row[uniqueid], $row[src]<br>";
      $row[uniqueid]=array("src"=>$row[src],"dst"=>$row[dst]);

$cars[]=$row[uniqueid];


   }

    /* free result set */
    mysqli_free_result($result);
}

$info=json_encode($cars);

print_r($info);

//else {

// printf("Error: %s\n", mysqli_error($link));

//}


/* close connection */
mysqli_close($link);
?>


[{"src":"+16145993800","dst":"s"},{"src":"+16145993800","dst":"600"},{"src":"+16145993800","dst":"600"},{"src":"100","dst":"500"},{"src":"+16145993800","dst":"600"}]

domingo, 5 de enero de 2020

creating json array object

<?php


$cars=array(array("name"=>"Ambiorix","lastname"=>"Rodriguez","age"=>38));


$info=json_encode($cars);

print_r($info);

?>

[{"name":"Ambiorix","lastname":"Rodriguez","age":38}]

viernes, 3 de enero de 2020

allow numbers

106
You can use preg_replace in this case;
$res = preg_replace("/[^0-9]/", "", "Every 6 Months" );
$res return 6 in this case.
If want also to include decimal separator or thousand separator check this example:
$res = preg_replace("/[^0-9.]/", "", "$ 123.099");
$res returns "123.099" in this case
Include period as decimal separator or thousand separator: "/[^0-9.]/"
Include coma as decimal separator or thousand separator: "/[^0-9,]/"
Include period and coma as decimal separator and thousand separator: "/[^0-9,.]/"