I know some web pages had very dynamic features, content and style but i had no idea creating such flexibility could be simply achieved with JavaScript code and CSS. Honestly, i thought many world recognised interactive and dynamic webpages like all Google sites and BBC online had to be created using some language other than HTML.(DISCLAIMER: the examples provided are not based on any substantial proof or evidence of the language used in their development). With this practical, i realised all you can see and wish to have a webpage do is simply hindered or made possible with your imagination. (i had for a long time underestimated the power of HTML)
With practical 3 the task was to create a table that had a context menu from which new rows could be added and the existing rows of the table edited or deleted. The objective was to understand dynamic HTML, practice manipulating HTML objects using script and write event handler JavaScript function and linking it to the events of an HTML object. In as much as i do not want to overestimate or exaggerate, i can sincerely say that the practical 3 came to me with a lot of surprises. The major one was how easy the concept and implementaion of a context menu is. Seriously, i never percieved a context menu as a simple DIV element the is made visible and positioned at the coordinate of the mouse or event that invoked it(so simple to do).
With this practical most of what we had to do was related to developing the functionalities to make the HTML element dynamic in nature. Firstly, on analysing the code we were given, i noticed that the function that allowed the displaying of the context menu and the other functions were uniquely attached to each of the four rows that were initially created. I started out to create dummy functions that would add rows and when the rows are clicked to simply pop an alert. I recognised that, the new functions did not respond to the dummy functions and no alerts were popped up when they were clicked. I played and experimented with the work alot to see the result of several ideas i thought of. For example, the question asked that the context menu should be showed when the table is clicked and i wondered if it could be done for the context menu to respond to a right click event. I searched and discovered that there was an "oncontextmenu" event handler but according to most online tutorials this was a component of HTML5. Despite this i tried it out in this practical, and though it was not recognized as a keyword by the editor i used it worked when i run the HTML document. There was however a little issue i just could not find a way around. The issue was that my customised context menu was always overshadowed by the browsers default context menu. Up until the time i had to submit the assignment, i could not find a way round it. Thankfully, i discovered the solution a few days ago, the simply solution was to invoke the "preventDefault" method on the "event" object in the function that did the displaying.
Focusing on the main tasking of the practical, one major challenged i had was obtaining the row index of the selected row the needed to be edited or deleted. I kept on having an undefined result when i tried alerting this index. Truthfully, this frustrated me for a long time and i had to abandon the work for a later time. After resting and taking another look at the code again, i realised the was another "onclick" event attached to the main DIV element that contained the whole table. The undefined result made sense then because the get row index function i was calling was rather being invoked on the div element, and that did not exist.
editing the content of a row |
Apart from the many challenges this practical presented, there were a lot of things i learnt. Some of them are, creating "design style" in classes using CSS so that they same design stlye could be applied to several elements, learning about the HTML event object, the concept of context menus, alternative ways of alerting the user when there is an error among many others.
In conclusion, one thing i also learnt from a friend after the assignment was instead of running through the collection of rows the table had in order to alternate the row style, CSS provided an easier option where in specifying the condition for the styling the rows, they would be automatically styled accordingly.