Forum Moderators: open

Message Too Old, No Replies

text link instead of a button

alternative to button on click event

         

humpingdan

11:20 am on Dec 2, 2003 (gmt 0)

10+ Year Member



I have a relativly simple javascript in one of my css pages:
it basically makes a div layer invisible then on a button press it becomes visible: (see below)

<script type="text/javascript">
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
if(document.layers) //NN4+
{
document.layers[szDivID].visibility = iState? "show" : "hide";
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState? "visible" : "hidden";
}
else if(document.all)// IE 4
{
document.all[szDivID].style.visibility = iState? "visible" : "hidden";
}
}
</script>

The buttons:

input type="button" onClick="toggleBox('book',1);" value="show div">

<input type="button" onClick="toggleBox('book',0);" value="hide div">

what i would like to know is there any other way of executing the script attached to the button, can i attach it to a href? so that when i click text it performs the javascript or does it have to be a button? any suggestions greatfully recieved, i dont really want to use the button formatting in css if i can help it!

Dan

Birdman

11:29 am on Dec 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Either of the examples below should work for you:

<a href="#" onclick="toggleBox('book',1)">show div</a>
<a href="javascript: toggleBox('book',1)">show div</a>

Regards,
Birdman

humpingdan

12:18 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



thank you :)