Change text for radio buttons - and for those already select

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Change text for radio buttons - and for those already select

Post by simonmlewis »

Code: Select all

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Online/Offline</title>
    </head>
    <body>
        <input type="radio" name="on/off" onclick="online();" /> Online
        <br />
        <input type="radio" name="on/off" onclick="offline();" /> Offline
        <br />
        <span id="update"></span>
        <script type="text/javascript">
            function online(){
                document.getElementById("update").innerHTML = "Online";
            }
            function offline(){
                document.getElementById("update").innerHTML = "Offline";
            }
        </script>
    </body>
This script is good, but what it doesn't do, is enable the "function" to show text if a Radio Button is "selected-selected".

I have three Radios, but one is selected by default to ensure the user has at least one clicked.
But it needs to show extra info - and then to change if another Radio is selected.

So is there something small I can add to just one of these radios or the Javascrpt to do that?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Change text for radio buttons - and for those already se

Post by social_experiment »

simonmlewis wrote:But it needs to show extra info - and then to change if another Radio is selected.
could you elaborate on this
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Change text for radio buttons - and for those already se

Post by simonmlewis »

Page opens.
Normally you select one radio button and text appears, or select another radio and that text disappears and another lots of text info appears.

I need the "selected='selected'" text (default selection) to already be showing, and then if you select another radio, that will disappear and another will show.,
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Change text for radio buttons - and for those already se

Post by social_experiment »

Like this ?

Code: Select all

<body>
	<input type="radio" name="on/off" onclick="basic();" selected="selected" />Default
	<br />
        <input type="radio" name="on/off" onclick="online();" /> Online
        <br />
        <input type="radio" name="on/off" onclick="offline();" /> Offline
        <br />
        <span id="update">Basic Text</span>
        <script type="text/javascript">
            function online(){
                document.getElementById("update").innerHTML = "Online";
            }
            function offline(){
                document.getElementById("update").innerHTML = "Offline";
            }
			function basic(){
				document.getElementById("update").innerHTML = "Basic Text";
			}
        </script>
    </body>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply