Coding

Ever since I advanced beyond the “hello worlds” of Java, I had never stopped coding. This section is for documenting code usages that I had employed while solving the technological problems that I had encountered.

How I used jQuery to push a dynamically generated file to the web browser based on the user’s input

There are times when we want to push a dynamically generated file to our users based on their inputs. That file could be an excel file that holds payment transaction reports for a time period or a tabulation of guest names who had accepted invitations to our corporate house warming.

In such cases, the user should be presented with a dialog box which lets him decide whether to save it somewhere in her local filesystem or open the file for viewing with an appropriate application in his computer.

For example, in my tool for generating boilerplate coding from a list of country names, I am presented with some input fields where I can submit some instructions to format the output of the boilerplate coding. And upon clicking on the “Generate” button, I am shown a dialog box that looks like the following:

Image of firefox dialog box after submitting request to generate some files.

Let’s cook up a simple scenario to demonstrate this idea with jQuery.

Suppose we are creating a simple game for the user to draw a random number. For this, we have a text field for the user to write his name. There will be a number dial that changes at random. When the user clicks on the “Get lucky number” button, the browser will present a text file for the user to download.

The text file will contain the user’s name and the number taken from the number dial at the instance when he clicks on the button.

SQL query to find foreign key constraints that reference columns in a table in oracle database

I was rather new to a system with hundreds of Oracle database tables. There was once when I realized that I had to delete a redundant row from the SYSTEMS_CONFIGURATION table.

As there are foreign key references to the SYSTEMS_CONFIGURATION table, I had to first remove all foreign key references to the redundant SYSTEMS_CONFIGURATION table row prior to deleting it.

This post captures the SQL query which I had ran on my Oracle database to find all the tables which had foreign key references to SYSTEMS_CONFIGURATION table, so that I can write the SQL update statements to delete all child references to the redundant SYSTEMS_CONFIGURATION row prior to deleting it.

How to use jQuery to detect user checking and unchecking a checkbox

I wanted to show / hide some input fields when a user checks / unchecks a checkbox on a web page.

To investigate how I can use jQuery to detect user checking and unchecking a checkbox, I cooked up a scenario.

There is a page with a HTML checkbox and a message. When the checkbox is checked, the message shows; if not, the message hides.

Pretty straightforward scenario to get me into working out a proof of concept to fulfill my objective.

How to use jQuery to access the DOM structure of parent HTML webpage from within the child HTML window

Sometimes, instead of showing a dialog box within a web page, it is more strategic to spawn a new HTML window as a dialog box to capture user input. This technique is especially useful when there are Java applets embedded in the web page, as Java applets tends to appear in front of every visual element on a HTML web page. There is no easy solution to place a visual element, for instance a HTML div, on top of Java applets.

Spawning another web page in another window is straightforward, but how do I send data collected from a child HTML window back to the parent HTML webpage? With this question in mind, I set out to find an answer.

How to use jQuery to intercept form submissions and validate form input

There came a time where I had to create a HTML form to accept inputs from users in order to generate a report. Before submitting the form to the back end server, there are some validations that I can perform on the data at the client side to reduce the number of HTTP responses that my server had to generate for unwanted inputs. The cost savings is especially significant when the form submission contains large file as part of the HTTP request.

I chose to use jQuery for intercepting the form submissions and do some data validation before I allow the browser to create a HTTP request to the server. This post documents a proof of concept, as a stepping stone, to realize my objective.