You shouldn t allow users to submit a web form until they have completed all the required fields. You should also validate fields on the client before submitting the form. In addition to reducing the load on the server by preventing invalid submits, this approach has the advantage of providing more immediate user feedback, which improves perceived performance. You can use a similar approach with links. For example, you might want to wait a few seconds after a page loads before enabling a link that refreshes the current page.

Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.

OnBarcode.com/GS1 - 13

<form> <input id="par" name="par" width="150" onkeyup="check(this)" /> <input id="sub" type="submit" value="OK" /> </form> <script type="text/javascript"> var s = document.getElementById('sub'); s.disabled = true; function check(v) { s.disabled = v.value.length < 3; } </script> It s important to revalidate data on the server since it is possible for hackers to bypass the script checks on the page. In fact, it s a good idea to log requests where invalid fields are detected on the server that should have been prevented by client-side script. In addition to being an indication of potential bugs in client or server code, they could also be indications of a security threat. JavaScript can also be used to avoid submitting a form if the selected parameters are the same as the ones that were used to generate the page. For example, you can prevent users from rerequesting a page if a selected sort key on a table is the same as the current one or if they are requesting the same page again (unless the content might have changed).

Here s an example that waits five seconds before enabling a Refresh link (see file20.htm): <a id="ref" dhref="file20.htm"></a> <script type="text/javascript"> var r = document.getElementById("ref"); r.style.color = "gray"; r.style.textDecoration = "underline"; var sec = 5; enableLink(); function enableLink() { if (sec > 0) { r.innerHTML = "Refresh available in " + sec + " seconds"; setTimeout("enableLink()", 1000); } else { r.innerHTML = "Refresh"; r.style.color = "black"; r.href = r.dhref; } sec--; } </script> You temporarily store the destination URL in a new property called dhref, and use setTimeout() to have the JavaScript runtime call you back once a second to provide user feedback. Without some user feedback, a disabled link on its own might be confusing. The first parameter to setTimeout() is the function name to call, and the second is the time interval in milliseconds. After five seconds, you activate

Using Barcode generator for Reporting Service Control to generate, create Barcode image in Reporting Service applications.

OnBarcode.com/Barcode

the link by setting the href property from the temporary dhref. This approach also helps prevent the cursor from changing to indicate that it s on a valid link when you hover over the text. To prevent the link from being disabled again if the user hits the back button in their browser to come back to this page from another one, you would need to record some state information on the client by setting a cookie from script. You should configure the cookie to expire quickly, probably after just a few minutes. It should have a path set on it, so that it s only attached to the minimum number of URLs possible. The script could then check for the presence of the cookie. If it s there, then the link can be enabled immediately. You can also disable a link after a user clicks it to prevent them from clicking twice. Here s an example that disables the link after a click, and then waits three seconds before navigating to the destination page, to give you a chance to see the disabled link (see file21.htm): <a id="some" href="file19.htm" onclick="disableMe(this);return false;">Go somewhere</a> <script type="text/javascript"> var v; function disableMe(val) { v = val; v.style.color = "gray"; v.style.textDecoration = "underline"; v.dhref = v.href; v.removeAttribute("href"); setTimeout("goSome()", 3000); } function goSome() { window.location.href = v.dhref; } </script> Since you start with a valid link in the <a> tag, when the user clicks, you move the destination URL from the href property to dhref and change the color and textDecoration style of the link text. Removing the href property prevents the browser from changing the cursor to indicate that the text is a valid link. Then you use setTimeout() to call a function after three seconds that will cause the browser to go to the new page.