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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Image Submit Button 1

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
How can I disable the Image submit button?

I have the following code:

<SCRIPT language=JavaScript> function Validate(FormName) {
if (FormName.FieldName.value == &quot;&quot;) {
alert(&quot;Field is Null&quot;);
return (false);
}
FormName.SubmitImage.disabled=true;
return (true);
} </script>
<form name=&quot;FormName&quot; action=&quot;test.html&quot; onSubmit=&quot;return Validate(this)&quot;>
<input name=&quot;FieldName&quot;><input type=&quot;Image&quot; src=&quot;Image.gif&quot; name=&quot;SubmitImage&quot;>
</form>
 
Um, programatically change the height and width values to &quot;0&quot;? ()even &quot;1&quot; might do it)

Sorry, it's a cheap-ass hack, I know, but I'm lazy and sometimes lazy people get things done quickly. Sloppily, but quickly.

I'm sure there's a much better answer elsewhere.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Disable how? It appears you already disabled the functionality of the image by returning false to the onsubmit event. Are you saying you want to make the image look disabled? If so you can do this in IE:
FormName.SubmitImage.style.filter='gray';
enable with:
FormName.SubmitImage.style.filter='';
 
Its not disabled, the code is not working, I want someone to debug it.
 
alsaffar-

Here is what your script does:

when the user presses the submit image, it executes the function [tt]Validate()[/tt], sending the form object [tt]this[/tt] as a parameter.

inside function [tt]Validate()[/tt]:
the text field value is tested....if empty or [tt]value==&quot;&quot;[/tt] then alert the user, and prevent the submit.

otherwise (if the field is not empty) disable the submit image, and allow the form to submit.


here is my question: why are you disabling the submit image, if the form is going to submit anyways?


&quot;Why is it always the quiet ones?&quot;

Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
AIM & MSN: robacarp
 
First of all, this form is not the real form that Im working on. The real one is so much complicated so I provided a sample form.

Then, why I want to disable the submit button, is because the submit button will insert a record in the database, so if the user keep hitting the submit button, so many records will be inserted!

Please help.
 
I see... well then, try this:
<SCRIPT language=JavaScript>
var submitted=false
function Validate(FormName) {
if(submitted){return false}
if (FormName.FieldName.value == &quot;&quot;) {
alert(&quot;Field is Null&quot;);
return (false);
}
submitted=true;
return (true);
} </script>
 
if all you want to do is stop someone from submitting twice the same form you can do this :

<input type=&quot;image&quot; onclick=&quot;this.disabled = true; return true&quot;>

Gary Haran
==========================
 
Gary, while it's good to disable the button like you say, the user could still submit the form by clicking in a text box and pressing Enter. I believe the best way is to return false to the onsubmit event.
 
Its not working at all :(

Please try to run my script and debug it please.

Please help guys
 
Here is code that works with IE 5+. However I am still not able to get it to work w/ NS. The only way it works with NS is if you uncomment the submit box.

<html><head><script language=&quot;JavaScript&quot;>
function disable(){
if (document.layers)
document.test.disabled = !document.test.disabled
Toggle(document.all.image1);
Toggle(document.all.image2);
Toggle(document.all.image3);
Toggle(document.all.image4);
alert(&quot;Mouse Clicked & Button Disabled&quot;);
alert (&quot;processing rest of function....&quot;);
}
function Toggle(objElement)
{
objElement.disabled = (!objElement.disabled)
if (document.layers)
{

//if (objElement.disabled && objElement.type.substr(0,6) == &quot;select&quot;)
// {
for (intI=0; intI<objElement.options.length; intI++)
{
objElement.options[intI].frozenStatus = objElement.options[intI].selected
}
//}

}
}
</script></head>

<body>
<form name=&quot;test&quot; onsubmit=&quot;if (this.disabled) return false; else alert('submitting')&quot;>
<input name=&quot;image1&quot; id=&quot;image1&quot; type=&quot;image&quot; src=&quot;/NJCLASS/img/buttons/clear.jpg&quot; border=&quot;0&quot; onClick=&quot;return disable();&quot;><br>
<input name=&quot;image2&quot; id=&quot;image2&quot;type=&quot;image&quot; src=&quot;/NJCLASS/img/buttons/exit-do_not_save.jpg&quot; border=&quot;0&quot; onClick=&quot;return disable();&quot;><br>
<input name=&quot;image3&quot; id=&quot;image3&quot;type=&quot;image&quot; src=&quot;/NJCLASS/img/buttons/save_and_exit.gif&quot; onClick=&quot;return disable();&quot; border=&quot;0&quot; ><br>
<input name=&quot;image4&quot; id=&quot;image4&quot; type=&quot;image&quot; src=&quot;/NJCLASS/img/buttons/submit_or_something.jpg&quot; onClick=&quot;return disable();&quot; border=&quot;0&quot;><br>
<!--input type=&quot;button&quot; name=&quot;ToggleButton&quot; value=&quot;Enable/Disable Form Elements&quot; onClick=&quot;return disable();&quot; -->
</form>
</body></html>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top