Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    19
    Thanks
    8
    Thanked 0 Times in 0 Posts

    onFocus textarea / radio buttons

    Code:
    <form action='webSurvey.php?action=addResults' method='POST' name='web_survey'>
    <table border='0' cellspacing='0' cellpadding='0'>
    	<tr>
    		<td>
    			<input type='radio' name='other_websites' value='1' id='other_websites1'> <label for='other_websites1'>Yes</label>
    		</td>
    		<td width='20'></td>
    		<td>
    			<textarea cols='40' rows='2' name='other_websites_specific'></textarea>
    		</td>
    	</tr>
    </table>
    	<br>
    		<input type='radio' name='other_websites' value='2' id='other_websites2'> <label for='other_websites2'>No</label>
    	<br>
    Is it possible to have the above so when I click the "no" radio button, the text in the textarea is cleared, and when the "yes" is click, the textarea becomes the focussed item?

    Thanks,
    Ed Ludlow

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Code:
    <script type="text/javascript">
    window.onload=function()
    {
    var noRadio=document.getElementById('other_websites2'), // Id of no radio button
    yesRadio=document.getElementById('other_websites1'), // ID of yes radio button
    txtArea=document.getElementsByName('other_websites_specific')[0]; // Name of textarea
    noRadio.onclick=function()
    	{
    	txtArea.value=''; // Remove the values of the textarea
    	}
    yesRadio.onclick=function()
    	{
    	txtArea.focus(); // Set the focus to the textarea
    	}
    }
    </script>
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    19
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Brilliant, thank you so much.

    About to attempt to add a feature so when you click into the textarea, the "yes" button is checked . . . . . . may be back in a bit

    Ed

  • #4
    New Coder
    Join Date
    Nov 2007
    Posts
    19
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Blimey I've got it work!

    Thanks again

    Ed


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •