Click to See Complete Forum and Search --> : [RESOLVED] create a text field based on radio button
icronex
06-12-2007, 11:38 AM
Hi
I have a problam with javascript errors.
I need to create a text filed dynamically when ever i selected one radio button .
Please help me and give me some example codes with similarlly.
i have two radio buttons with "yes" and "no".
so 1) Appear create a text filed when i click on "YES" radio button.
2) Diss appear when click on another radio button "NO".
please give me code
thanks
Kudose
06-12-2007, 07:00 PM
Only because you asked nicely and it was a nice refresher for me ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<script type="text/javascript">
<!--
function checkRadio(){
var radios = document.getElementsByName('myRadio');
if(radios[0].checked){
var radioValue = 'yes';
} else {
var radioValue = 'no';
}
var magicArea = document.getElementById('magicArea');
if(radioValue == 'yes'){
var myInput = document.createElement('input');
myInput.setAttribute('type', 'text');
myInput.setAttribute('name', 'myInput');
myInput.setAttribute('id', 'myInput');
magicArea.appendChild(myInput);
} else {
magicArea.removeChild(document.getElementById('myInput'));
}
}
//-->
</script>
</head>
<body>
<label for="yes">Yes</label><input type="radio" name="myRadio" value="yes" onchange="checkRadio()" /><br />
<label for="no">No</label><input type="radio" name="myRadio" value="no" onchange="checkRadio()" /><br />
<div id="magicArea"></div>
</body>
</html>
icronex
06-22-2007, 03:56 AM
Than Q fro giving this code
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.