0

Hi
I want to set focus to a text field on a php page which is loaded by ajax.
The javascript file for ajax is shown below

<script>
function menu_change(str)
{
	 
	
  if (window.XMLHttpRequest)
  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  }
  else
  {
	  // code for IE6, IE5
  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		
    	        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
				
    }
  }
if(str==1)
  {
    xmlhttp.open("POST","index_search.php",true);
  }
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=1");

}

</script>

The php file index_search.php is shown below.

<body>
<form action="index.php" method="get" name="f" >
  <div align="center">
    <table width="633" height="232" border="0">
	<caption class="lab">
	<h2 class="style1">
	INDEX SEARCH</h2>
	</caption>
      
      <tr>
        <td width="206" height="53" class="style24">Enter Keyword to Search </td>
        <td width="417">
          <input name="srch_txt" type="text" id="t" class="input_st2"  size="35" >
        </td>
      </tr>
      
      <tr>
        <td height="39" class="style24">Specify Text Position </td>
        <td colspan="2" >
          <input name="txt_pos" type="radio" value="start" />
          <span class="style25">Starting          </span>
          <input name="txt_pos" type="radio"  value="end" />
          <span class="style25">
                  Ending</span>
        <input name="txt_pos" type="radio"  value="any" checked="checked" />
        <span class="style25">Anywhere</span>
        <input name="txt_pos" type="radio"  value="equal" />
        <span class="style25">Exactly</span> </td>
      </tr>
      

      <tr>
        <td height="54" colspan="3"><div align="center">
                     <input name="index_srch" type="hidden" class="butt_s"   id="simple_srch"   value="Find"   />

            <input name="index_srch2" onclick="indx()" type="button" class="butt_s"   id="simple_srch"   value="Find"   />
            
        </div></td>
      </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
    </table>
  </div>
</form>
</body>

I used document.f.srch_txt.focus() .But it not working..

Can someone show me how?
Thanks

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by divyakrishnan
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.