2

I've an textbox in asp.net,when i enter ";" semicolon in textbox means it have to call a function.Is there any way to do this.please help me out guys..i tried change function but it calls at every keypress in textbox.

$('#prgrp').on('change', function (evt)
            {
                var txt = $("#prgrp").val();
                var valueArray = txt.split(';');
                var valueSortArray = valueArray.sort();
                var duplicateValues = [];
                for (var i = 0; i < valueSortArray.length; i++)
                {                     
                    if (valueSortArray[i + 1] == valueSortArray[i])
                    {
                     duplicateValues.push(valueSortArray[i]);                            
                    }
                }
                if (duplicateValues.length > 0)
                {
                 $("#duplicate").html("Don't enter repeated values");
                 $('#duplicate').css('color', 'RED');
                 $("#prgrp").autocomplete("disable");
             }
             else {
                 $("#duplicate").html("");
                 $("#prgrp").autocomplete("enable");
             }
         });
3
  • 1
    Show some code,what you have already tried! Commented Mar 12, 2015 at 10:18
  • i posted my code rahul. Commented Mar 12, 2015 at 10:22
  • Did my answer helped you? If so do accept it as answer :) Commented Mar 12, 2015 at 14:50

3 Answers 3

2

Try this:-

$("#prgrp").keypress(function (e) {
     if (e.keyCode == 59) {
         //Call your function here
     }
});

Please note, you can also use e.which in place of e.keyCode as it is jquery standardized.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this

$('#prgrp').bind('keypress', function(e) {
var code = e.keyCode || e.which;
 if(code == 59) { //
   //Do something
 }
});

Demo

Comments

1

try this code

$( "#prgrp" ).keypress(function( event ) {
    if ( event.which == 59 || event.keycode == 59 ) {
        //your function call
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.