jQuery .val() supports select elements

Did you know that you can get selected options for select elements with simple jQuery .val() method?

Somehow I was under impression it only scrapes “value” attribute, which is not the case for select element and used to look for selected option element. However, recently I found that .val() it works fine for both drop-down and multi-select elements. In the latter case it even returns an array of selected values.

Still you need something like $(‘#mySelect’).find(‘option:selected’).text() if you’re looking for user-friendly label of selected element(s) rather than it’s value attribute. And still .val() doesn’t work for radio-buttons as they are multiple elements.

Avoiding emails sent from PHP getting blocked by Gmail

Many times I had problems with emails sent from my applications were rejected by Gmail. One of customers told me that adding “Return-Path” header with the same address as “From” field should fix that and it worked like a charm! Quite interesting as I never found this documented.

Also, to avoid getting your emails filtered as “spam”, you can add SPF and DKIM records. The easiest way is to enable it directly on the mail server so you don’t have to change your PHP code at all. On cPanel it’s just a matter of setting two checks on Email Authentication page. I wish they were checked by default.

Beware: Estimated result count in Google AJAX Search API is incorrect

If you need to get Google search result count for some query, using estimatedResultCount from Google AJAX Search API sounds like a winner. However, the number reported as estimatedResultCount doesn’t match the number displayed on regular search pages and could be different in many times. This is known issue since 2008 and it seems it will never be fixed.

So if you want more correct result count, the extract it from regular Google search page. Alternatively you can use Yahoo or Bing APIs as they report the same numbers to displayed on their regular search pages.

UPDATE: It was found that regular Google search pages display even more rough estimated result count than Google AJAX Search API. For example, query for "pumka.net" (w/ quotes) it reports "About 1,380 results" while only finds 284 pages. Bing reports 55 results while finds 50-52 and Yahoo reports 210 results while finds 55. So using Bing or Yahoo API for analysis of result counts is likely more accurate.