Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSubmit, show/hide

Status
Not open for further replies.

dkirkdrei

Programmer
Dec 14, 2007
5
US
I have a form in which I am trying to hide the submit button once it has been clicked and replace it with a gif image. The code that I am trying is below but I cannot get it to work. Right now both elements show up at the same time. Please help!

<script type="javascript">
function onSubmit(){
document.getElementById('submitButton').style.display = "none";
document.getElementById('progressBar').style.display = "block";
}
</script>

<form action="..." onSubmit="return onSubmit()">
.....
<div id="submitButton">
<input type="button" value="submit">
</div>
<div id="progressBar" style="display: hidden">
<img src="progressbar.gif">
</div>

</form>
 
I'm not an expert on Javascript, but maybe you can try this instead:

document.getElementById('submitButton').style.visibility = 'visible';
document.getElementById('progressBar').style.visibility = 'hidden';
 
also, I think you can do a conditional test beforehand.
(once again I am not a Javascript expert)

if((document.getElementById('submitButton').style.visibility != 'visible') && (document.getElementById('progressBar').style.visibility != 'hidden'))
{
document.getElementById('submitButton').style.visibility = 'visible';
document.getElementById('progressBar').style.visibility = 'hidden';
}

Or something like that (I don't think you need it though)
 
forgot to add on more to that:

function onSubmit()
{
if((document.getElementById('submitButton').style.visibility != 'visible') && (document.getElementById('progressBar').style.visibility != 'hidden'))
{
document.getElementById('submitButton').style.visibility = 'visible';
document.getElementById('progressBar').style.visibility = 'hidden';
}

else { document.getElementById('submitButton').style.visibility = 'hidden';
document.getElementById('progressBar').style.visibility = 'visible';
}

}


Hey, I'm learning just like anyone out there lol!
 
hey expertnovice, thanks for the response. I finally got it working, see below:

<html>
<head>
<title>Submit Hider</title>

<script type="text/javascript">
function onSubmitButton(){
document.getElementById("submitButtonDiv").style.display = "none";

if (navigator.appName == "Microsoft Internet Explorer") {
document.getElementById("progressBar").innerHTML = "";
document.getElementById("progressBar").style.display = "block";
document.getElementById("progressBar").innerHTML = "<img src='progressbar.gif' alt='Progress Bar'>";
} else {
document.getElementById("progressBar").style.display = "block";
}
}
</script>
<body>
<form action="" onsubmit="return onSubmitButton()">
<div id="submitButtonDiv">
<input type="submit" value="submit">
</div>
<div id="progressBar" style="display:none">
<img src="progressbar.gif" alt="Progress Bar">
</div>

</form>
</body>
</html
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top