HOME   SITEMAP   CONTACT   NEWS   BLOG
Search


JavaScript Miscellaneous


Pushing submit buttons twice

This is a very easy but effective way to stop impatient users push submit buttons more than once. Once pushed, the buttons becomes disabled (not pushable anymore) and changes its text to "Please wait ..." (or whatever you want).

<form name="myExampleForm" action="foo.php">
  <input 
    type="submit" 
    name="mySubmitButton" 
    value="Submit Form" 
    onclick="
      this.disabled=true; 
      this.value='Please wait...'; 
      document.myExampleForm.submit();
    "
  >
</form>

Proper way of using popups

First of all, don't use popups. There are only a few rare cases i can think of that justify to use popups.

The goal is to make it work for everyone. If someone has javascript disabled, it should open the popup url in a new browser window.

And if the popup is already open, but maybe hidden behind other windows, let it bring on top.

link text

<a 
  href="http://www.blueshoes.org/" 
  target="_blank" 
  onclick="
    w=window.open(
      this.href, 
      'windowName',
      'toolbar=no,scrollbars=no,resizable=yes,width=500,height=350'
    ); 
    w.focus(); 
    return false;
  "
>link text</a>
If the javascript executes, it opens up the window, brings in to the front, and then returns false so that the href is not followed. Otherwise, the href is followed and a new browser window is opened.

Removing the scrollbars is ok, but please keep the window resizable. There are always reasons for your content to need more room than you thought.