Hello,
I have the part of code presented below.
It has 2 radiobuttons and 2 text inputs.
When user selects the first radiobutton(value="searchw"), I would like to make textsearch1 enabled and textsearch2 disabled.
And the opposite process..
when user selects the second radiobutton(value="searcht") I would like to make textsearch2 enabled and textsearch1 disabled.

html code:

<form name="definesearch" action="#" method="post">
  <br />
  <br/>
<table>
  <tr>
    <td><input type="radio" name="searche" value="searchw" />
      search writer</td>
    <td><input type="text" name="textsearch1" onkeyup="writer(this.value)" disabled="disabled"/></td>
  </tr>
  <tr>
    <td><input type="radio" name="searche" value="searcht" />
search themes</td>
    <td><input type="text" name="textsearch2" onkeyup="themes(this.value)" disabled="disabled"/></td>
  </tr>
</table>
<br/><br/>
</form>

and here is my javascript effort (which is maybe wrong?? it doesn't work :( )

<script>
function definesearchmode()
{
	if (document.definesearch.searche.searchw.checked=true) 
	{
		document.definesearch.textsearch1.disabled=false;
		document.definesearch.textsearch2.disabled=true;
	}
	else if (document.definesearch.searche.searcht.checked=true)
	{ 	
	document.definesearch.textsearch1.disabled=true;
	document.definesearch.textsearch2.disabled=false;
	}
}
</script>

I call the script from here: <body onLoad="definesearchmode()" >


I am newbie to javascript, code has some errors probably that I don't know how to figure it out...


Any help would be appreciated :)

Member Avatar for rajarajan2017
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script language="javascript">
function alter(id)
{
	if (id=="1") {
		document.frm1.text1.disabled=false;
		document.frm1.text2.disabled=true;
	}
	else {
		document.frm1.text1.disabled=true;
		document.frm1.text2.disabled=false;
	}
}
</script>
</head>
<body>
<form name="frm1">
<input type="radio" name="changer" value="Test1" onclick="alter(1)" checked> Test1<br/>
<input type="text" name="text1"><br/>
<input type="radio" name="changer" value="Test2" onclick="alter(2)"> Test2<br/>
<input type="text" name="text2" disabled>
</form>
</body>
</html>

Test it.

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.