jQuery – Validate the form when the submit button is clicked

Here is a simple jQuery script which could use the validate a mandatory input.

(function ($) {
  $(document).ready(function() {    
    $('#<submit-button-id>').click(function(event){    
      var x = $('<input-id>').val();
      if (x == null || x == '';) {
        alert('Please fill in the input.');
        event.preventDefault();
      }
    })
  });
})(jQuery);

 

Done =)

Reference: StackOverflow – Intercept a click on submit button and check validity of form jQuery

Drupal – Disable the default node page

In Drupal 6, the default <front> page has the path /node which will list out the latest nodes. Although we could point the <front> page to another path, the /node page is still accessible.

Create a custom module and add the following piece of code would help redirecting /node page back to the <front> page.

/**
 * Implementation of hook_menu_alter().
 */
function YOUR_MODULE_NAME_menu_alter(&amp;$items) {
  $items['node']['page callback'] = '_internal_custom_function_name_here_redirect_to_frontpage';
}

/**
 * Redirect back to the frontpage for specific pages.
 */
function _internal_custom_function_name_here_redirect_to_frontpage() {
  if($_GET['q'] == 'node') {
    $_REQUEST['destination'] = &quot;&lt;front&gt;&quot;;
    drupal_goto();
  }
}

 

I haven’t tried it in Drupal 7, please let me know if you have any idea.

Done =)

Reference: disable the default node page

Garbled characters when opening CSV in Microsoft Excel

Quite often i will use Microsoft Excel to edit CSV file. But sometimes you may find garbled characters in the opened file and it is caused by the file encoding.

For example, Excel could not view UTF-8 file. So if you got a CSV encoded in UTF-8, you need to convert it to ANSI encoded. This could be done by opening the CSV file in Notepad and then save it as new file in ANSI encoding. Continue reading Garbled characters when opening CSV in Microsoft Excel

陶傑 – 這一次難搞了

「國民教育」還可以賴曾班子埋炸彈,新界東北的大切割,深圳大陸人免簽進出「深港同城化」的大計,是梁振英「競選」時寫過的政綱、講過的「願景」,文字和聲檔還在,這下子比較討厭:臨時降格為只為香港人建設的衞星房屋城區,香港人即使集體老人癡呆,那麼近的言行全部都沒了記憶,往電腦一點擊,梁特言論紀錄全部可以Recall,要通通否認,眼睛不眨一下,極品的說謊天才,也做不到。

最好笑是香港規劃署副署長梁焯輝,重複深圳一個官員的指示,透露:「大陸人民,很想去香港看電影、飲茶,但不想每次遠去尖沙嘴中環,在新界北複製一個銅鑼灣出來,像時代廣場,附戲院食肆,就會有市場。」

深圳福田、廣州天河,都有商場。如果掃LV,大陸有關稅,非要來新界東北不可,那麼飲茶、看電影,蝦餃燒賣,深圳廣州沒得吃?《蝙蝠俠》第三集,大陸沒得看?香港酒家的廣東點心,為節約成本,本錢向地產商交租,都是在深圳工場廉價造好的,冰凍了再運過來,深港一旦邊境「同城」,深圳人還會來新界北一起地溝油融合飲茶?完全不合常識。
Continue reading 陶傑 – 這一次難搞了

陶傑 – 變詐

梁班子強推「國民教育」,幾乎搞得全城起義。「知識份子」支持學生絕食反抗,不少「學者」,私下呻吟:當初支持梁×英,看錯了人。

為什麼看錯人?只怪「知識份子」學藝未精。

當初看唐梁競「選」,他們見到唐唐表現儍儍的,似富家紈袴子弟,相反,梁×英能言善道,滿肚子鴻圖大計,比較「西方」,而梁×英模仿美國的奧巴馬,喊一個字:Change,更令特區「知識份子」感動落淚,認為救主降臨。

美國的奧巴馬叫Change,你也學着叫,這就叫「領袖魅力」?「知識份子」出問題的地方,就在這裏。

Change,是什麼?不錯,就是「變」。但這個字,只適用於西方,中國人的社會國情,是另一回事。
Continue reading 陶傑 – 變詐

Superfish – Add active class to current menu link

Superfish is a jQuery plugin for creating drop down menu. You can download it @ GitHub – karevn / superfish.

It works well but there is no CSS class for identifying the menu item of the current page. Luckily i found a solution in StackOverflow.

The following jQuery code will find out the menu item which match the current URL and add the active class to it. Continue reading Superfish – Add active class to current menu link

Dream BIG and go for it =)