...

View Full Version : onFocus textarea / radio buttons



eludlow
10-09-2008, 10:58 AM
<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

rangana
10-09-2008, 11:11 AM
<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>

eludlow
10-09-2008, 11:17 AM
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

eludlow
10-09-2008, 11:22 AM
Blimey I've got it work!

Thanks again :thumbsup:

Ed



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum