Some basic on Javascript that not all programmers are aware

These are some of the JavaScript way of writing that one usually do not know by learning on some basic web site such as w3schoo.com

Declaring many variables at once

You can declare many variable at once by doing the following,

var test,test1,test2,test3,test4
OR
var test=1,test1=2,test2=3,test3=4,test4=5

Assignment operator shortcuts

you can do a assignment operator in short instead of writing long code.

x+3=x -> 1+=3
x-4=-x -> x-=4
x*1=x -> x*= 1
x/1=x -> x/=1
x+1=x -> x++
x-1=x -> x--

The "with" statement

The 'with' statement basically help you reduce some code. The meaning of with can be read as 'with this'. For example,

<script type="text/javascript">
document.write('Hi there, how are you?")
document.write('Fine, thanks. And you?')
document.write('Great!')
</script>

You can write as

<script type="text/javascript">
with(document)
{
write('Hi there, how are you?")
write('Fine, thanks. And you?')
write('Great!')
}
</script>

By using the 'with' statement, everything that falls inside of its brackets ({ }) default to the object specified in it's parameter. That way, you only need to type the object name once.

Remember, the "with" statement can be used with any JavaScript object to avoid having to repeatedly write the object out when referencing it multiple times.

The "?" conditional expression statement

This is a shortcut for if-else statement and it will return a Boolean value. For example, instead of writing this

if(x==1)
do something..
else
don't do it..

We can write something shorter such as this,

x==1 ? do something.. : don't do it..

The format for this is as follow,

(condition) ? doiftrue : doiffalse

Conclusion

The reason for doing all these shortcut is to improve efficiency of the code to help improve performances. Especially on large application where efficiency holds a key to whether its a good or bad application. Every line of code contribute greatly on the performance of the application. One will have to remember that speed in web application holds a key on whether anyone will visit or use your application/site.

Free Web Hosting

i was quite surprise with web hosting nowadays. Although free web hosting has been around for quite sometime, but there will always be ads banner or certain restriction that will link on your site because the service is free. Nowadays, there isn't any ads and the service provided and is equally comparable with the service given by paid hosting! Furthermore, it's TOTALLY FREE! (ah..its better than paid hosting in my country =/)

i went to google it up and found quite a few free hosting chart that show list of free hosting services. However, the same things happen with free web hosting which i though only happen with paid hosting is that there are many bad quality service although their marketing strategy looks very attractive. The 'bad' quality i am referring here is the number of downtime and their terms and condition that users do not read. Most of these free attractive hosting plans have terms which will cause your site to be removed. Some even cause your site to be down for a week/month/year because they do not really care about what happen to your site since its free. Thus, finding good quality free hosting is important if you want your site to remain alive and don't feel con after all the work you have done to get your hosting up.

Personally, i do not know any free hosting site that may worth to try but i do believe the following site may hold some interest for those who are searching desperate for it:

  1. http://www.000webhost.com/
  2. http://www.110mb.com/

Seriously, i am not doing any affiliate program for the above site. (if i am, it will be a link instead of a site url) I believe if you come in this topic and this site you are most likely someone i know or desperate for a hosting plan. If you would like to share your hosting experience with everyone, please post it up here so that people are aware.  But if you are looking for a paid hosting plan i will have an idea and if you guys really like to know, you can email me if you want to or leave a post =)

Cheers,

Clay Lua

CSS: Box Model Problem/Hack

The problem caused by different browsers way of interpreting a CSS element has emerge the need of CSS hack. The box model hack was developed by Tantek Celik, the lead developer of Internet Explorer for the Mac to solve the issue on IE 5 border and padding problem. The total width of the box SHOULD be calculated by adding the border thickness on the left and right, the padding on the left and right and the width of the content. Thus, Consider the following code:

<code>#test{
background: #ff8132;
border: 5px solid #ff0000;
padding: 15px;
width: 100px;
}
</code>

The above code should create a box with a 5-pixel border and 15 pixels of padding around the content which has a 100 pixel width. This gave a total width of 140 pixels.

Unfortunately, some common browsers ( IE 6 and below) interpret this code incorrectly, Instead of applying the width to the content area, the width restrains the overall box size, so that the border and padding subtracted from the over width! So we are left with a box 100pixels width, but a content area only 60 pixel wide!!( width - left and right border+padding = 60 pixel)

This cause cross browser issues when displaying the same box on for example, IE and Firefox! Firefox will display a box of total width 140 pixel while IE will only display the same box with a total width of 100 pixel! To fix this, we need to use a hack, that is, we have to intentionally introduce code that doesn't work in one browser so that both boxes have the same width.(writting  a code that work in IE but fail in firefox so that both of them have 140 pixel)

We will be taking advantage of a bug in IE that causes it to ignore certain CSS so that it set the true width:

<code>#test{
background: #ff8132;
border: 5px solid #ff0000;
padding: 15px;
<span style="color: #ff0000;">voice-family: "\"}"\";
voice-family: inherit;</span>
width: 100px;
}
</code>

But this will caused problems in Opera unless we add a definition after the above code

<code>html>body #test{
width: 100px;
}</code>

This allows browsers that understand the parent/child selector grouping to correctly interpret your code. Nowadays, with IE 7 came along, this problem will not be shown on the newer browser but for older browser on old pc this is still a problem. Other than the box model problem, presently there are still problems exist on today browsers due to different implementation and interpretation by these browsers. The need of CSS hack is still needed so that cross browser issues caused by CSS can be eliminated.

Point to consider when building a dynamic site

Understanding layout on Web

All web layouts have two basic parts. The first part is the content area while the other part is filler. Based on this balance, there are four broad categories of web layout.

  • Unrestrained. The content is allowed to stretch horizontally from the left edge to the right edge of the window and vertically down to the bottom edge of the window which eliminate the needof filler.
  • Fixed width. The content is given a set fixed size on its width, restraining the content horizontally.
  • Fixed height. The content area is given a fixed length on its height, restraining it vertically.
  • Fixed size. Both height and width are given a fixed width restraining the content regardless of screen size.

Understanding Hypertext, Navigation  and Controls

  • Navigation: these are links used to move the visitor between different general sections and pages within the site
  • Controls: these are links or buttons used to perform a specific action, such as submit a form
  • Hypertext: these are links used to display additional information about the specific text being linked.

Four D's of Web Design

  1. Define
  2. Design
  3. Develop
  4. Deploy

Define

In order to start designing a site, one have to collect, identify, and distill the information that will make up your site.

  • Collect your content
  • know your audience
  • establish your goals
  • plan features and interactivity
  • consider the graphic design style

These are the points must be taken into consideration when defining and planning the site.

Design

  • Outline the site
  • create a site map
  • Sketch the layout grid
  • create a storyboard
  • define the look and feel

these are the points needed before designing the site.

Develop

  • prepare the content
  • create the code
  • create a template
  • Assemble the pages
  • test your site

Deploy

The web site may be built and tested and its now ready to go live!

HTML: Values and Units

Length values

Length values come in two varieties:

  • Relative lengths, which vary depending on the computer being used.
  • Absolute values, which remain constant regardless of the hardware and software being used.

Relative lengths values:

  • em: Em dash
  • ex: x-height
  • px: pixel

Absolute length values:

  • pt: Point
  • pc: Picas
  • mm: millimeters
  • cm: centimeters
  • in: Inches

Color values

Color can be written in different way,

  • #RRGGBB
  • rgb(R#, G#, B#)
  • rgb(R%, G%, B%)
  • name

Percentage

The behavior of percentage value depends on the property being used.

URLs

A uniform resource locator (URL) is the unique address of something on the Web.  URL can be written so that it cancel itself

<a href="#">Link</a>

or

<a href="javascript: void('')">Link</a>

In some situation placing any URL in the href will interfer with the DHTML functions so the latter code will be used instead. These function simply tells the link to do absolutely nothing.