Adding confirm dialogue box for delete links with jQuery

Categories: Tips, blog, code



I use this all the time. Its simple, clean and gracefully degrades. Even though its simple some people might miss it. So I post it here.

$('.delete').click(function(){
    if(!confirm('Are you sure you want to delete?'))
    {
        return false;
    }
})

By returning false you stop any action from the link (redirecting you to the url)

You can see the demo here.

Debugging an SQL Query

Categories: Tips, Troubleshoot, blog, code

So, I debugged an error for a good friend recently. Only certain kind of item would be displayed, everything else was not found in the search. The first thing I suspect is the SQL Query. I printed out the SQL Query and tried to debug it.

The first thing I did is to arrange the SQL Query in a readable manner.

Since I do not have the time to follow the trail from the SQL Query manually, I just comment out 3 conditions at a time, and add a condition each time until the item was found. In the above picture, I’ve found the culprit its the one below the commented out line.

When I commented out the line, the results for the keyword appeared as follow.

So thats the divide and conquer part. So now I know the problem is with the commented out criteria and the one below it. I traced it back to its table (products_to_categories) and found out that the category_id value is empty. Thats why it can’t join in with the categories table and thus there’s no result.

So what did I do? I told my friend about the problem, explained it to him (I gave him a couple of screenshots to explain the problem) and gives him a solution. UPDATE products_to_categories SET categories_id = xx. So that all the item have a category and will be displayed when it is searched by the application.

Erm, yeah. Thats about it.

Retrieve the content of FCKEditor

Categories: Tips, code

Here’s an interesting problem that I faced few days ago on MyQuotes. I wanted to apply a lightbox kind of preview for the content the user put in. I use FCKEditor for the textarea. I have no idea how to retrieve the contents from the textarea (to put it into the lightbox).

After googling around ( I forgot the keyword that I used ), I found it, it can be retrieved using FCKEditor’s API.

oEditor = FCKeditorAPI.GetInstance('quote'); 	
myValue = oEditor.GetXHTML(oEditor.FormatOutput);

The FCKEditor is using BBCode, to minimize abuse (hope it works! LOL). Since I don’t know how to convert the bbcode values retrieved from the content into HTML tags, I use the next best thing. Send it to be converted and tagged up using jQuery’s $.post().


MyQuotes Screenshot

Focus on first input text in jQuery

Categories: Development, Tips, code

I’m doing a little bit of polishing while finishing up some forms. I got this fade-in effect and wants to get the first input text to be focused when the animation ends.

function show_form(formname)
{
    hide_all();
	$('#' + formname).css('opacity', 0).parent().show();
    $('#' + formname).animate({opacity: 1}, 'normal', function(){

		// focus on the first input in the form
		$('#'+formname+' input:text:first').focus();

		offset = $('#add_new').offset().top;
		$('html, body').animate({
                 scrollTop: offset }, 2000);
	});

    return false;
}

 There’s an additional effect in that function. It’ll scroll down to the form because there’s a list above the form, so, it’ll just scroll right pass it.

On Estimation…

Categories: Development, Notes, Tips, blog

Here’s an entry on the wiki on Estimation. Since we got a few new guys (some are trainee), I thought it might help them. Below is an example of an estimation writeup.

What is Online Trial Exam Form?

A small application to allow users to register (to participate in an online trial exam) and the admin to process the registrants.

Important: If asked to give an estimate on the spot, please, tell them you’ll comeback later. Take at least 1-2 hours in breaking down tasks and estimation.

estimate.jpg

The user (we will use the term admin here, the person who request the application) requires the following function (user requirements) :

  • The user (potential students) can enter in their information to participate in a trial exam.
    • Get the fields required. Ask which field is mandatory and why if it is not obvious (one of the obvious field is email, of course email is mandatory or else how do the system inform the user how to participate in the trial exam). 30 minutes.
    • Each registration have a time-frame. i.e. Each day starts from 5am to 5pm. If a user registers on 30th August 2008 @ 5.01pm, it will count as the user registers on 31st August 2008.1 hour
  • The admin can view list of dates (or we can call a time-frame, as each day starts from 5am to 5pm, beyond that will spill into the following day’s date) and total of registration for each date.30 minutes
  • The admin can view list of students in a given date. 30 minutes
  • The admin can process a given date.
    • The system will iterate through list of registrant and send an email containing the details required to use the online examination system. 1 hour
    • The admin can reprocess a given date (skips users who have been processed). 30 minutes

Continue reading On Estimation……

On forgetting passwords..

Categories: Development, Tips

I have lots of web applications that I installed to try out and evaluate. Sometimes I come back to them to look up on some flows that are getting me stumped. And when that time comes, I usually forget the password and all that I can see in the tables is just hashes. All is lost? No. There is hope!

sc_7-25-2008-112808-am.jpg

So, what to do with the hash? Most probably your local application is using simple default password. If you still can’t remember, just head over to GData: An Online MD5 Hash Database and put in your hash and it’ll retrieve the original string. Easy.

If the hash is not stored in GData, you could always overwrite the hash by creating your own hash. For me I use PHP, and I use phpinteractive as a shell. Type in the commands for md5 and there it is, the hash. Copy the hash and replace it in the table field. New password!

Be aware that some application uses salt for creating passwords and you have to know how the password is salted, whether it uses the last 3 characters of the password and some stuff like that.

How to open .docx file in OpenOffice 2.3? (in Windows)

Categories: Tips

As I was trying to resume my work, I realized I have a .docx that I needed to open, most of the info is in there. The problem is I don’t use Microsoft Office, I’m using OpenOffice 2.3. Googled around a bit and found, Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats.

Installed it without any problems, there’s no shortcut or anything to run the program. I double-clicked the .docx file and it runs the Microsoft Open XML Converter and I can save it to .doc format. After saving it, I double-clicked the .doc file and the converter runs again, trying to convert it into another format.

Went to the properties of the file and change the Opens with to OpenOffice Writer. Finally, I can resume my work.

Cannot delete folder: Access is denied

Categories: Tips, Troubleshoot

Ever stumble upon this message while trying to delete a file or a folder?

Cannot delete folder: Access is denied

Make sure the disk is not full or write-protected and that the file is not currently in use

sc_5-15-2008-115311-am.jpg

Most probably you have, and most probably doesn’t know how to handle this.

Continue reading Cannot delete folder: Access is denied…

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.