javascript problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • renoua
    New Member
    • Jun 2010
    • 11

    javascript problem

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

    html code:

    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 :( )
    Code:
    <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="defines earchmode()" >


    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 :)
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    I appreciate the effort. You have done a good job. There is no need to call any function on body onload. Instead of that give that function in input radio onclick.

    Code:
    <input type="radio" name="searche" value="searchw" onclick="definesearchmode()" />
    give the same for another radio button also. This will work fine.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    Working...