Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Using JQuery Array

10:12 AM | , , , , , , , , ,

1. Array Push

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi")

The result of fruits will be:
Banana,Orange,Apple,Mango,Kiwi

2. Remove Array Elemen

var y = [1, 2, 3];
var removeItem = 2;

y = jQuery.grep(y, function(value) {
  return value != removeItem;
});
or
var y = [1, 2, 3];
var removeItem = 2;
y.splice( $.inArray(removeItem, y), 1 );
or
var y = [1, 2, 3];
y.remove(2);
The result of fruits will be:
1,3


Read More

Redirect Page and Send Some Post Data

7:28 PM | , , , , , , , ,

Iseng-iseng bikin fungsi untuk redirect form sekaligus mengirimkan data dengan method POST tanpa menggunakan ajax. Fungsi ini gunanya untuk mengirimkan data sekaligus redirect ke halaman tertentu tetapi variabel yg dikirimkan berbeda-beda pada beberapa kasus.

function redirect_post($url, array $data) {
?>
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
       <script type="text/javascript">
           function closethisasap (){
               document.forms["redirectpost"].submit();
           }
       </script>
       <body onload="closethisasap();">
           <form name="redirectpost" method="post" action="<? echo $url; ?>" >
               <?
               if (!is_null($data)) {
                   foreach ($data as $k => $v) {
                       echo '<input type="hidden" name="'.$k.'" value="'.$v.'"> ';
                   }
               }
               ?>
           </form>
       </body>
   </head>
</html>
<?
exit();
}

Cara pemanggilan fungsinya:

$data['varname1'] = "value1";
$data['varname2'] = "value2";
$url = "Some location";
redirect_post($url, $data);
Read More