0

If i write some thing in input field and then i pressed enter then it should alert the specific value.Here is the code. please help me

<html>
<input type="text" class="searchfld" id='input' onchange="gotothatpost(this.value)"onkeyup="ajxsrch(this.value,getAscii())">
</html>
<script>
function ajxsrch(str,asci)
{
  if(asci==13)
   {
    alert("You pressed enter");
   }
  else
   {
    do something;
   }
}
</script>

1 Answers1

1

I am assuming you want us to define the getAscii() function for you. Using code partially modified from this answer, the following example should work.

<html>
<input type="text" class="searchfld" id='input'  onkeyup='ajxsrch(this.value, getAscii(event))'>
<script>
function getAscii(e) {
    if (window.event){ // IE                    
       return e.keyCode;
    }else {
         // Netscape/Firefox/Opera                  
        return e.which;
    }
}
function ajxsrch(str,asci)
{
  if(asci==13)
   {
    alert("You pressed enter");
   }
}
</script>
</html>
Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329