By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,001 Members | 451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,001 IT Pros & Developers. It's quick & easy.

Textbox appearing after radio button is selected--new code

P: 19
I changed my code...Now everytime i click a radio button, a text box appears...What i want is when i hit a particular radio button, the textbox should only appear next to that radio button. And if another radio button is selected, then the 1st textbox should disappear and should display in front of the new radio button selected.

Following is my code:

<html>

<head>

<script type="text/javascript">

function Markit(name) {

if (name == 'a')
{

var txtInput = document.createElement("INPUT");
txtInput.type="text";
txtInput.id="txtInput"
txtInput.value=" ";
txtInput.size="30"
DivAppend.appendChild(txtInput);


}

if (name == 'b'){
var txtInput = document.createElement("INPUT");
txtInput.type="text";
txtInput.id="txtInput"
txtInput.value=" ";
txtInput.size="30"
DivAppend.appendChild(txtInput);


}
}
</script>

</head>

<bodyonLoad="appendObj();">
<div id="DivAppend">
</div>



<br />

<input onclick="Markit('a')" type="radio" name="a" value="y">Male
<br />

<input onclick="Markit('b')" type="radio" name="a" value="n">Female
<br />
</body>
</html>


Thanks
Jan 9 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,892
Have you thought about putting the radio buttons and text boxes in a 2 column table?
Jan 9 '07 #2

acoder
Expert Mod 15k+
P: 16,027
This is a Javascript problem. Are you sure you want to create a new text box every time a radio button is clicked or do you want to move the text box from one radio button to the other?

If you want to move then you should move the div instead of creating a new object every time. If you want to delete the old object, you need to remove it from the div. At the moment, your code adds text boxes with the same name to the div each time a radio button is clicked and the div appears before the radio buttons.

Why not define two divs, one after each radio button? When a radio button is clicked, the div corresponding to the radio button shows its text box and hides the other one using
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(object).style.visibility = 'visible'
and
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(id).style.visibility = 'hidden'
respectively.
Jan 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.