Web Hosting Directory | Web Hosting Resources | Webmaster Resources | Domain Tools | Search Engine Marketing | Forums
  Signup
Today: 30   Yesterday: 1,557   Max: 1,872   Total: 377,305   Current Users : 10 (Member 0) 
DOMAIN TOOLS

WEBMASTER TOOLS

RELATED ARTICLES

SUBMIT AN ARTICLE

Write for us and get publicity, link to your website, and best of all get paid. Please visit our writers page for details.


LINK TO US

Link to us and earn points for each visitor you bring to us. Please visit our link partner page for details.

 

Submit Image Changes When Data is Ready

In this variation on the Rollover Submit Image, the image changes not when the mouse is over it but when the user has typed something into the fields. The image changes to signal that the form is ready for submitting:
To create this type of image submit, first copy this script exactly as is into the <HEAD> section of your page:

<SCRIPT TYPE="text/javascript">
<!--
// Script by Idocs Inc, http://www.idocs.com
// Distribute freely, but keep this notice in place
var swrlist = new Array();

function swapwhenready(ready, notready)
{
this.ready=ready;
this.notready=notready;
this.alt="submit query";
this.name=document.forms[document.forms.length-1].name;
this.setfields     = swr_setfields;
this.checkfields   = swr_checkfields;
this.write         = swr_write;
this.submitswap    = swr_submitswap;
swrlist[this.name] = this;
}

function swr_setfields()
{
this.fields = new Object();
for (var i=0; i < arguments.length; i++)
   this.fields[arguments[i]]=true;
}

function swr_checkfields()
{
var myForm=document.forms[this.name];

for (var i=0; i < myForm.elements.length; i++)
   {
   if (
      (myForm.elements[i].value.length == 0) && 
      (this.fields ? myForm.elements[i].name && 
      this.fields[myForm.elements[i].name] : true)
      )
      return false;
   }
return true;
}

function swr_write()
{
if (
   document.images && 
   (document.forms.length > 0)
   )
   {
   this.readyImage = new Image();
   this.readyImage.src = this.ready;
   this.notReadyImage = new Image();
   this.notReadyImage.src = this.notready;
   this.imagename = this.name + '_swrimage';
   this.linkname = this.name + '_swrlink';

   document.write(
      '<A ' + 
      ' HREF="javascript:submitit(\'' + this.name + '\');void(0);"' + 
      ' NAME="' + this.linkname + '"' + 
      '><IMG SRC="' + this.notready + '"' + 
      ' ALT="' + this.alt + '"' + 
      ' NAME="' + this.imagename + '"' + 
      ' BORDER=0');
   if (this.height)document.write(' HEIGHT=' + this.height);
   if (this.width)document.write(' WIDTH=' + this.width);
   if (this.otheratts)document.write(" " + this.otheratts);
   document.write('></A>');
   }
else
   {
   document.write(
      '<INPUT TYPE=IMAGE SRC="' + this.ready + '"' + 
      ' ALT="' + this.alt + '"');
   if (this.otheratts)
      document.write(" " + this.otheratts);
   document.write('>');
   }
this.submitswap();
}

function submitswap(myfield)
   {swrlist[myfield.form.name].submitswap()}
function swr_submitswap()
{
if (this.checkfields())
   document.images[this.imagename].src = this.readyImage.src;
else
   document.images[this.imagename].src = this.notReadyImage.src;
}

function submitcheck(myform)
   {return swrlist[myform.name].checkfields()}

function submitit(name)
{
if (swrlist[name].checkfields())
   document.forms[name].submit();
}

//-->
</SCRIPT>

Now, suppose our form has one field we want filled in before the form is ready. Let's say the form is named "myform" and the field to check is named "searchstring". We create the form like this:

<FORM 
   ACTION="../cgi-bin/mycgi.pl"
   NAME="myform" 
   onSubmit="return submitcheck(this)">

<INPUT 
   NAME="searchstring" SIZE=10
   onKeyUp="submitswap(this)"
   >

<SCRIPT TYPE="text/javascript">
<!--
var swapper = new swapwhenready("search.ready.gif","search.notready.gif");
swapper.write();
//-->
</SCRIPT>

<NOSCRIPT><INPUT TYPE=SUBMIT></NOSCRIPT>

</FORM>

Search!
"search.notready.gif"
Search!
"search.ready.gif"



Copyright 1997-2002 Idocs, Inc. Written by Miko Sullivan.

 
 
What is your major source of website traffic?
 
 
 
 
 
 

ADVERTISEMENT

 
Cheap Web HostingBudget Web HostingEcommerce Web Hosting
Link to UsLink ExchangeAdvertisePrivacy PolicyTerms Of ServiceAbout UsContact UsSitemap
Copyright © 2006 - 2008 Broadband Media, Inc. All rights reserved.