Entries Tagged 'HTML' ↓
June 7th, 2008 — HTML
If you ever come across a situation where your page goes to the same action twice for no apparent reason then make sure that there’s no background=”#” anywhere in your page.
I found that if there’s background=”#” then the page tends to submit the same request twice!! Call it a bug in html… Not sure about that. But the code is as below:
<table background=”#”>
<tr>
<td>
This piece of code in your page will cause the request to be submitted twice!!
</td>
</tr>
</table>
Please leave a comment if you have anything to add to this
March 14th, 2008 — HTML
This is going to be a small post. There’s not much to talk about.
HTML has an event called “oncontextmenu”. This event handles the right click event.
So, if you want to disable right click for any field in your page, all you have to do is add “oncontextmenu” inside the particular tag. The example below will make things clear.
Ex. Suppose you want to prevent users from copy pasting something into one of your text boxes. Then you need to write the input tag as follows:
<input type=”text” oncontextmenu=”return false;”>
That’s it!! The context menu does not appear because we are handling the right click event by returning false.
Alternatively, you can disable right click for the whole page as follows:
Just copy paste the following code after the end of your <form> tag.
<script>
document.oncontextmenu = function(){return false}
</script>
January 25th, 2008 — HTML, JavaScript
In most of the search pages you might have noticed how you can type your queries into the search box and search by pressing the enter key instead of having to click the ‘Search’ button present in the page.
Wondering how to do it? Well, wait no more. Implement the same feature in your pages too.
All we need to know is the key code for the enter key which happens to be ‘13′.
Then under the event onKeyDown we can call the javascript which submits the page.
Go through the example below and you’ll know it all.
{
<input type=”text” onKeydown=”Javascript: if (event.keyCode==13) Search();”>
<input type=”button” value=”Search” onClick=”Search();”>
}
The above code will display a text box followed by a button labelled Search as shown in the figure below:(Note: Click on the thumbnail to view)

You’ll notice that the onClick event of the Search button calls a javascript function named Search(). To have the same function called on pressing the enter key when the cursor is in the text box, we check if the keycode is 13 and subsequently call the Search() function.