[Javascript] Replace submit button upon click...

Chris Tifer christ at saeweb.com
Mon Mar 17 08:26:03 CST 2003


I'm not exactly sure of the problem, so maybe I'm wrong here, but if
I get the gist of your problem correctly, it'd be best to include one
bit of code that loops through the forms collection after the page loads
and adds an onSubmit handler to each of them.

It shouldn't matter if there's more than 1 form on the page.  I whipped up
a small example of what I THOUGHT you might be talking about. It is
just 2 simple forms with a submit button in each. If you click one, it'll
switch
to say "Pending". It doesn't remove the button, but there's other ways of
disabling it, such as setting a variable that states the button has been
pushed
and if they try to push it again, just "return false" and maybe send them an
alert letting them know.

===========================================
<HTML>

<form name="Test1">
<input type="submit" value="Submit">
</form>

<form name="Test2">
<input type="submit" value="Submit">
</form>


<script language="Javascript">
document.onload = findForms()

function findForms(){
 for(var x = 0; x < document.forms.length; x++){
  document.forms[x].onsubmit = alertMe
 }
}

function alertMe(){
 var objForm = document.forms[this.name]

 for(var x = 0; x < objForm.elements.length; x++){
  if(objForm.elements[x].type == "submit"){
   objForm.elements[x].value = "Pending"
  }
 }

 return false
}
</script>

</HTML>
===========================================

Hope that helps,

Chris Tifer
http://www.emailajoke.com


----- Original Message -----
From: "Chris Nafziger" <CNafziger at sauder.com>
To: <javascript at LaTech.edu>
Sent: Friday, March 14, 2003 4:29 PM
Subject: RE: [Javascript] Replace submit button upon click...


> I believe there are no pages containing more than one form.  The
declaration
> you specified requires modification of each form, correct?
>
>
> -----Original Message-----
> From: David T. Lovering [mailto:dlovering at gazos.com]
> Sent: Friday, March 14, 2003 4:12 PM
> To: javascript at LaTech.edu
> Subject: Re: [Javascript] Replace submit button upon click...
>
>
> A couple of questions --
>
>   Is this all one form, or multiple forms?  If all the pages hang off of
> one form, you could use a single 'onValidate' declaration in the form
> header itself to forward control to a single routine which would terminate
> with a return 'true' to continue with the CGI/BIN (or whatever) receipt
> of the form data, yet issue the 'pending...' dialogue beforehand.
>
>   If these are multiple forms, the matter is a bit trickier...
>
>   -- Dave Lovering
>
>
> Chris Nafziger wrote:
> >
> >    Part 1.1Type: Plain Text (text/plain)
>
> In a controlled environment (IE 5+), is it possible have a function, that
> can be included in any page, that replaces a submit button with the
contents
> of a string, and submits the form, when the button is clicked, without
> having to specify the onClick event for submit buttons throughout the
site.
> I'm looking for a little function to put in an ASP include that is
included
> on each page of the site, which will effectively make the text
"Pending..."
> appear, each time a submit button is clicked, with no work involved other
> than creating the function, and putting it in the include.  Obviously, the
> forms must still submit properly.  You DOM gurus out there... can you
point
> me in the right direction please?
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list