PDA

View Full Version : How do I test if a button is present?


ScottInTexas
12-16-2002, 02:33 PM
I have a button in an iframe that is written only when data is in another frame. The problem is that the button is toggling there and not there. Following the program with alerts, it is getting written whenever the data is updated in the other frame, but if it was already present it gets erased. I want to test to see if the button is there and if it is just skip the routine.




function SetPrintButton(){
var objFrame=self.frames["printFrame"];
objFrame.document.write('<input type="button" id="printit" value="Print Table" onclick="parent.doPrint()">');
}



Thanks for the help,

Leon
12-16-2002, 03:21 PM
Try this:


function SetPrintButton(){
var objFrame=self.frames["printFrame"];
var oBtn = objFrame.document.all("printit");
if (oBtn == null){
objFrame.document.write('<input type="button" id="printit" value="Print Table" onclick="parent.doPrint()">');
}
}

ScottInTexas
12-16-2002, 03:37 PM
Hi Leon,

I couldn't seem to get a pointer to the button object. I tried a lot of different combinations of getElementById etc. I tried the all collection but my syntax was wrong. Thanks for helping me out and getting it right.