Архив метки: how to

How to disable "Enter Key" to submit?

<form action=»foo»>
<input type=»text» onkeypress=»return bar(event)»>
<input type=»submit»>

<script type=»text/javascript»>
function bar(evt){
var k=evt.keyCode||evt.which;
return k!=13;

Note however that this «enter» key behavior isn’t standard (and actually behaves differently across user agents); moreover this won’t prevent you from full server-side checking, as a client can have javascript deactivated (or even trick your javascript at runtime).

foreach in JavaScript

Actually that’s not true at all.
As all javascript objects are really just associative arrays, there is a foreach like syntax for the ‘for’ construct.
Without it it would be very hard to work with many common javascript objects.
It’s actually very simple to use and incredibly useful if you like associative arrays.

You just have to make sure to use it on an associative array and not an object.
Example below

Continue reading “foreach in JavaScript” »