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

determine if a button exists

Status
Not open for further replies.

crabgrass

Technical User
Aug 29, 2007
111
US
I need to disable a button IF it exists. Something like

if (document.forms[0].cmdPeople1){
document.forms[0].cmdPeople1.disabled = true ;
}

Would there be a correct syntax for this?
 
You're on the right track. Did you try the code to see if it works?


Here's an example:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

window.onload = function () {
   var a = document.getElementById("blah");
   var b = document.getElementById("i_dont_exist");
   if (a) {
      alert("blah is disabled");
      a.disabled = "disabled";
   }
   if (b) {
      alert("i_dont_exist is disabled");
      b.disabled = "disabled";
   }
};

</script>
<style type="text/css"></style>
</head>
<body>

<input type="button" value="click me" id="blah" />

</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top