Click to See Complete Forum and Search --> : Disabling menu link
tech_talker
July 27th, 2005, 09:37 AM
Hi,
I'm quite new to JScript and html pages.
Depending on the selection of the Radio button on a html page a menu item link on the html page has to be enabled or disabled.
By default the menu item is not to be present and it is only on the selection of the radio button the menu link gets enabled.
Can anybody let me know how do i mix formatting with Java script. In short how do I check the value of a flag(set on selection of radio button) to determine the appereance of the Menu link.
olivthill
July 27th, 2005, 01:25 PM
Here is an example
<html>
<head>
<script language=javascript>
function enable_link()
{
document.getElementById("link1").innerHTML="<a href=\"javascript:alert('Cool');\">Click on this cool link</a>";
}
function disable_link()
{
document.getElementById("link1").innerHTML="<a disabled><u>It's useless to click on this cool link</u></a>";
}
</script>
</head>
<body">
<form>
<input type=radio name=r1 value=v1 checked onclick="enable_link()">Enable link
<br>
<input type=radio name=r1 value=v2 onclick="disable_link()">Disable link
</form>
<p>
<span id="link1"><a href="javascript:alert('Cool');">Click on this cool link</a></span>
</body>
</html>
tech_talker
July 28th, 2005, 07:47 AM
Thanks for the update.
I was wondering what has to be done so that the link should not be present at all in the document. It is only when the radio button is selected that the link comes on the document.
olivthill
July 28th, 2005, 08:45 AM
In my example above, you replace
function disable_link()
{
document.getElementById("link1").innerHTML="<a disabled><u>It's useless to click on this cool link</u></a>";
}
by
function disable_link()
{
document.getElementById("link1").innerHTML="";
}
The principle is that I use a "span" thing (I'm not sure if it is a true "object" or not), named "link1" in my example.
Then I can put everything I want into that span thing, such as a href link, or nothing, with the "innerHTML" or "innerText" property.
The span thing is very useful. It is similar to the "div" thing, except that "div" always takes at least an entire line, whereas the span thing has the width of the things it contains.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.