Solved

Replace submit button with image when clicked

Posted on 2006-11-20
7
223 Views
Last Modified: 2008-02-01
Can someone come up with a short JS that changes a form's submit button to an image when it's clicked?

I'd like to display an animated gif progress bar which would be displayed where the submit button was after the user submit the form.
0
Comment
Question by:cbradstreet
7 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 17984318
Check this out:


<html>
      <head>
            <title>Script Demo</title>
            <script language="JavaScript">
                  function swapMe(){
                        document.getElementById('imgT').style.display="inline";
                        document.getElementById('sbmit').style.display="none";
                  }
            </script>
      </head>
<body>
<form name="temp" onsubmit="alert('Check your Button')">
      <input id="sbmit" type="submit" value="Submit Me" onClick="javascript:swapMe();"><img style="display:none" id="imgT" src="max.jpg">
</form>
</body>
</html>
0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 17984412
<form name="f1">
<input type="image" src="image1.jpg" onclick="this.disabled = true;">
</form>

0
 

Author Comment

by:cbradstreet
ID: 17984608
Hmm ... this *doesn't* seem to do the trick ... ;-)

<html>
<head>

<script language="JavaScript">
function swapMe(){
document.getElementById('imgT').style.display="inline";
document.getElementById('sbmit').style.display="none";
}
</script>

</head>

<body>

<form name="temp">
<input id="sbmit" type="submit" value="Submit Me" onClick="javascript:swapMe();"><img style="display:none" id="imgT" src="http://www.listmedia.com/graphics/progress-bar.gif">
</form>

</body>
</html>

Ideally, I want a regulat submit button, and then when user clicks the button the progress-bar.gif image appears in place of the button while my script processes the page and then proceeds to the next page.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 50 total points
ID: 17986221
How about this:

<html>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<form name="temp">
<input id="sbmit" type="submit" value="Submit Me" onClick="this.style.display='none';document.images.imgT.style.display='';"><img style="display:none" name="imgT" src="http://www.listmedia.com/graphics/progress-bar.gif">
</form>
</body>
</html>


0
 
LVL 3

Assisted Solution

by:viveksg
viveksg earned 50 total points
ID: 17993327


<html>
<head>
<title>Zvonko &#42;</title>
<script>
function fn_Submit()
{
   document.getElementById('sbmit').style.display = 'none';
   document.getElementById('imgT').style.display = 'block';

   return true;
}
</script>
</head>
<body>
<form name="temp">
<input id="sbmit" type="submit" value="Submit Me" onClick="return fn_Submit()">
<img style="display:none" name="imgT" src="http://www.listmedia.com/graphics/progress-bar.gif">
</form>
</body>
</html>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now