user3570689
user3570689

Reputation:

Every time when i pressed the enter key then it should alert some thing

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>

Upvotes: 0

Views: 35

Answers (1)

merlin2011
merlin2011

Reputation: 75575

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>

Upvotes: 1

Related Questions