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

Button question and embed question

Status
Not open for further replies.

codeone

Programmer
Mar 25, 2003
343
US
This is a two part question...

first:
is there a way to apply an if statement to a button, like you can with a checkbox....

ex:
if(document.alpha.beta.checked)

but I want to do this with a button...

second:
is it possible to load and play a sound file without first embeding the sound in the doc?

thanks

code one
 

code one,

Not sure about the sound file... But the button won't have a 'checked' property, I wouldn't have thought.

What property would you want to check?

Dan

 
i know it wouldnt have the checked property but I was addressing that as an example, I would like to check for the onclick....

is that possible?
 
codeone,

to check for a click you simply assign a function to the button's onclick handler

<script type=&quot;text/javascript&quot;>
function checkForClick() {
alert(&quot;i've been clicked&quot;);
}
</script>

<input type=&quot;button&quot; onclick=&quot;checkForClick();&quot; value=&quot;click me&quot;/>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Or if you want to test to see if it has an onclick event assigned to it, you could use:

Code:
alert(document.getElementById('buttonID').getAttribute('onclick'));

Dan
 
I figured it out and I used:

if(document.form.bttnName.click)

that worked exactly like I wanted...

thanks for your reply
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top