hello
i have problem with radio in this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" />
<script>
function add()
{
var radio=document.getElementsByName("t");
var d=document.getElementById("div");
if(radio[0].checked==true)
{
d.innerHTML+="<p><input type='text' id='txtfname'><br />";
d.innerHTML+="<p><input type='text' id='txttxtlname'><br />";
d.innerHTML+="<p><input type='submit' value="">";
}
if(radio[1].checked==true)
{
d.innerHTML+="<p><input type='text' id='code'><br />";
d.innerHTML+="<p><input type='submit' value="">";
}
}
</script>
</head>


<body>
<form method="post" >
<table >
<tr>

<input type="radio" id="name" name="t" value="name"  /></td><td> </td><td>
<input type="radio" id="code" name="t" value="code" /></td><td></td></tr>
<tr>
<td><p><input type="button" value="Add" onclick="add()" class="btn"/></p></td></tr>
<tr><td>
<div id="div">
</td>
</tr>
</div>
</table>
</form>
</body>
</html>

Hi there,

i have seen you code and there is some errors in code, see this code block, hopefully this will helpful for you

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" />
<script>
function add()
{
var radio=document.getElementsByName("t");
var d=document.getElementById("div");
var a=document.getElementById("name");
var b=document.getElementById("code");
	if(a.checked)
		{
			d.innerHTML+="<p><input type=\"text\" id=\"txtfname\"><br />";
			d.innerHTML+="<p><input type=\"text\" id=\"txttxtlname\"><br />";
			d.innerHTML+="<p><input type=\"submit\" value=\"\">";
		} 
	else if(b.checked)
		{
			d.innerHTML+="<p><input type=\"text\" id=\"code\"><br />";
			d.innerHTML+="<p><input type=\"submit\" value=\"\">";
		}
}
</script>
</head>
<body>
<form method="post" >
  <table >
    <tr>
      <td><input type="radio" id="name" name="t" value="name"  /></td>
      <td><input type="radio" id="code" name="t" value="code" /></td>
    </tr>
    <tr>
      <td><p>
          <input type="button" value="Add" onclick="add()" class="btn"/>
        </p></td>
    </tr>
    <tr>
      <td><div id="div"> </div></td>
    </tr>
  </table>
</form>
</body>
</html>

Best,

Rahul Dev Katarey

thanks for reply
i solve my problem
with this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" />
<script>

function add()
{
var radio=document.getElementsByName("t");
var d=document.getElementById("div");
if(radio[0].checked==true)
{
d.innerHTML+="<p><input type='text' id='txtfname'><br />";
d.innerHTML+="<p><input type='text' id='txttxtlname'><br />";
d.innerHTML+="<input type='submit' value='Search'/>";

}
if(radio[1].checked==true)
{
d.innerHTML+="<p><input type='text' id='code'><br />";
d.innerHTML+="<input type='submit' value='Search'/>";
}
}
</script>
</head>


<body>
<h1 align="center" dir="ltr" >به نام خدا </h1>
<form method="post" style="text-align:right;">
<table align="right">
<tr>

<td><p><h3 align="right" dir="ltr">جستجو بر اساس </h3></td><br  />
<tr><td>
<input type="radio" id="name" name="t" value="name"  /></td><td>نام </td><td>
<input type="radio" id="code" name="t" value="code" /></td><td>کد</td></tr>
<tr>
<td><p><input type="button" value="Add" onclick="add()" class="btn"/></p></td></tr>
<tr><td>
<div id="div">
</td>
</tr>
</div>
</table>
</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.