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

Disabling an image button 2

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi,

I am trying to disable an image button but it says it is null or not an object - where am I going wrong please?

<form name="form" method="post">
<input type="image" name="submitbutton" src="button.jpg" height="30">
</form>

<script>
{
form.submitbutton.disabled=true;
}
</script>

Thanks very much

Ed
 
Hi

The correct reference would be :
Code:
[red]document.[/red]form.submitbutton.disabled=true;
But that not matters in current situation anyway, because [tt]input[/tt]s of [tt]type[/tt] [tt]image[/tt] can not be referred by [tt]name[/tt]. They are neither included in [tt]elements[/tt] collection. ( [tt]document.form.elements.length[/tt] of your above [tt]form[/tt] is 0. )

Give it an [tt]id[/tt] and refer it using [tt]getElementsById()[/tt] :
Code:
<form name="form" method="post">
<input type="image" name="submitbutton" [red]id="submitbutton"[/red] src="button.jpg" height="30">
</form>
JavaScript:
[red]document.getElementById('[/red]submitbutton[red]')[/red].disabled=true;

Feherke.
 
That's fantastic - exactly what I needed.

Thanks very much indeed.

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top