Category

# Common JSP/HTML & Javascript Problems

31 / Aug / 2012 by Vivek Sachdeva 0 comments

Some of the commonly faced problems are:

1) In case we give different width combinations for cells of different rows, the width combination of first row is accepted and subsequent combinations are neglected.

```
&amp;lt;tr&amp;gt;
&amp;lt;td width=&amp;quot;30%&amp;quot;&amp;gt;1.1&amp;lt;/td&amp;gt;
&amp;lt;td width=&amp;quot;50%&amp;quot;&amp;gt;1.2&amp;lt;/td&amp;gt;
&amp;lt;td width=&amp;quot;20%&amp;quot;&amp;gt;1.3&amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;

&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;50%&amp;quot;&amp;gt;2.1&amp;lt;/td&amp;gt;
&amp;lt;td width=&amp;quot;40%&amp;quot;&amp;gt;2.2&amp;lt;/td&amp;gt;
&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;2.3&amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;

```

In this case width of first, second and third cell would be 30%, 50% and 20% for both the rows.

2) If we have defined width combinations for first row cells and we use both colspan and width attribute for cell of other row, then width attribute becomes ineffective.

If we want to have table as shown above, we can have each row with one cell and each of the cells would have a table with single row. That ways, the cells of the row can be arranged as per our specifications and requirements.

```
&amp;lt;tr&amp;gt;
&amp;lt;td&amp;gt;
&amp;lt;table border=&amp;quot;2px&amp;quot; width=&amp;quot;100%&amp;quot;&amp;gt;
&amp;lt;tr&amp;gt;
&amp;lt;td width=&amp;quot;80%&amp;quot;&amp;gt;New&amp;lt;/td&amp;gt;
&amp;lt;td width=&amp;quot;20%&amp;quot;&amp;gt;Few&amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
&amp;lt;/tr&amp;gt;

&amp;lt;tr&amp;gt;
&amp;lt;td&amp;gt;
&amp;lt;table border=&amp;quot;2px&amp;quot; width=&amp;quot;100%&amp;quot;&amp;gt;
&amp;lt;tr&amp;gt;
&amp;lt;td width=&amp;quot;40%&amp;quot;&amp;gt;New&amp;lt;/td&amp;gt;
&amp;lt;td width=&amp;quot;60%&amp;quot;&amp;gt;Few&amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
&amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;

```

3) One of very common problems that we face in when working with javascript is that we do not get to know what error exactly occurred if the script is not working as expected. We can use try-catch blocks, just as we do in java.

A very basic example:

```
function division(){
try{
var c = 1/x;
}

catch(e){
alert(&amp;lt;a href=&amp;quot;http://e.name&amp;quot; target=&amp;quot;_blank&amp;quot;&amp;gt;e.name&amp;lt;/a&amp;gt; + &amp;quot; &amp;quot; + e.message)
}
}

```

Some javascript errors and their description:

Hope it helps.

Regards.

Vivek Sachdeva

vivek.sachdeva@intelligrape.com

@vivek_sach

### Tag -

HTML/UI/CSS javascript jsp try Try catch
FOUND THIS USEFUL? SHARE IT
Services