Posts

Showing posts with the label WEB

Get the Values of all SPAN Elements with the same Class Name using jQuery

I am using the snippet below on one of my blogs in blogger to dynamically get the classname of a span element which contains a text of the post ID of the entry and process the iframe tags within that element. $(document).ready(function(){ $.each($('span.post-id'),function(i,v){ var s = $(this).text(); getiFrame(s); //this is a separate function to process iframe tags. }); });

How to Extract Data From HTML (.aspx) website into Excel using VBA

Image
In this example I used the following VBA code to extract the data stored in a script variable. You can see the example data from an HTML file at the end of this post. Below is the snapshot of the page that I was trying to extract data from. VBA CODE: '******************************************************** ' DESCRIPTION: GET DATA FROM TABLE OF A .ASPX WEBSITE ' BY: CROMWELL D. BAYON ' EMAIL: OMELSOFT@GMAIL.COM '******************************************************** Sub GetOfflineData() Dim file As String, Data As String Dim delimQ As String Dim lineContentLoc As Long delimQ = Chr(34) file = Application.ActiveWorkbook.Path & "\Source of Select.html" Open file For Input As #1 Do Until EOF(1) Line Input #1, linefromfile 'Check only the line containing this pattern (var best_idear_data =[) If InStr(1, linefromfile, "var best_idear_data =[...

Handle Keypress Event on a Search Box in jQuery

Image
I have this problem before when I tried to search a keyword from a database using jQuery-AJAX-PHP. Where in the query is fired up multiple times which slows down process. After searching reading various solution for this problem. I've came up with the jQuery function below. This handles the keypress event of the textbox with an id keyword . $('#keyword').live('keypress', KeywordSearch); Javascript Function: function KeywordSearch(event) { if (event.handled !== true) { if (event.keyCode == 13){ var type = $('#searchType').val(); var keyword = $('#keyword').val(); var result = $.ajax({ type: "GET", url: "search.php?keyword=" + keyword + "&type=" + type, async: false}).responseText; $('#results').html(result); $('#myTable').fadeIn('fast'); event.handled = true; event.preventDefault(); } } }

Create Pagination Using jQuery-PHP-Ajax on a Webpage

Image
In this tutorial, I'll be showing you a basic example on how to create Pagination on your website. The purpose of this is just to give basic logic of how it was created. So, let's get it started. First, we will create the PHP file to print out the page ranges. We have two parameters $LIMIT and $RANGE that is passed by an Ajax request via jQuery. $LIMIT - This is the limit of rows per page to be displayed. $RANGE - Initially, this is set to 1. This is the pages range that will be displayed. It will decrement/increment as you click the Next or Previous buttons. Additional parameters... $MAX - The maximum number of pages to be shown in a range. This example shows 10. $RECORDS - Get the total number of records in the database table. $PAGES - This is the quotient of the $RECORDS divided by the $LIMIT . Then we do some conditional statement to print out the pages, next and prev button. PHP File (pages.php) <?php include "js/pagination.js...

jQuery event.keyCode | event.charCode | event.which - Code Generator

Image
Key event handling is not that easy after all. However, it's more advisable to reliably get character codes during the keyPress event. There are two different types of codes: 1.)   event.keyCode: Keyboard Codes that Returns the Unicode value of a non-character key in a keypress event or any key in any other type of keyboard event. 2.) event.charCode: Character Codes that Returns the Unicode value of a character key pressed during a keypress event. In this tool I was using jQuery events to get the corresponding event codes of the keys the user pressed. CODE: $(document).ready(function(){ $('#key').live('keypress', processKeyPress); $('#key').live('keydown', processKeyDown); $('#key').live('keyup', processKeyUp); function processKeyDown(e) { processEvent('keyPress', e); } function processKeyPress(e) { processEvent('keyDown', e); } function pro...

Display Unique Number Values in a string using PHP

The funciton DisplayUniqueValues() will let you remove the duplicate values from a string array of numbers and sort out the resulting value that will be displayed. Code: <?php function DisplayUniqueValues($NumArray) { //Remove the duplicated values $uniques = array_unique(explode(",", $NumArray)); //Sort out the unique values $result = sort($uniques, SORT_NUMERIC); //Combine the result in a string using the separator ',' $result = implode(',', $uniques); return $result; } //USAGE $str_num = '12,13,14,12,12,12,12,11,14,90,78,78,91,90,92,89'; echo DisplayUniqueValues($str_num); ?> Output should be: 11,12,13,14,78,89,90,91,92

Password Generator Function in PHP

The following GeneratePassword() function lets you to create a random password whether for your custom site or for personal use. The function contains 1 parameter which is $len . $len - The number of password characters. You can also define the set of characters "CHARS" on your parent class. Code: <?php define("CHARS", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_+@(!)<>"); function GeneratePassword($len = 10) {     $pass = ''; //Initialize random password variable     $char = str_split(CHARS);     $count = strlen(CHARS) - 1;     for ($i = 0; $i < $len; ++$i)     {         $index = rand(1, $count);         $pass .= $char[$index];     }         return $pass; } ?> Usage: <?php       echo GeneratePassword(12); ?>  ...