views:

947

answers:

3

Hello,

I have some input (text type). I'd like to the same behavior for all except for one.

I tried this :

$(document).ready(function() {

    $("input[type=text]").bind('keydown', function(e) {
     ....
    });

    $("#MyOtherInput").keydown(function(e) {
     .....
    });

});

MyOtherInput is the input type texte with a specific behavior ....

Could you help me ?

Thanks,

A: 

Just unbind the event on the field that requires a specific event.

$("#MyOtherInput").unbind("keydown").keydown(function(){});
Nando Vieira
+1  A: 

Try this:

$('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e)
{
    ............
});

It will select all the input with type text except myotherinput control.Try below example.

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;

</head>
<body>
    <div id="testdiv">
        <input id="Text1" type="text" /><br />
        <input id="Text2" type="text" /><br />
        <input id="Text3" type="text" /><br />
        <input id="Text4" type="text" /><br />
        <input id="Text5" type="text" /><br />
        <input id="Text6" type="text" /><br />
        <input id="MyOtherInput" type="text" />
    </div>
</body>

<script type="text/javascript">

    $(function()
    {
        $('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e)
        {
            alert('Common for all ');
        });

        $('input[type=text]#MyOtherInput').bind('keydown', function(e)
        {
            alert('Only for MyOtherInput');
        });        

    });

</script>

</html>
Raghav Khunger
and with 2 exceptions ?
Kris-I
Assign any separate class to that two controls suppose the name of that class is testclass.The your code will be like this: $('input[type=text]').not('input[type=text].testclass').........
Raghav Khunger
A: 

You can use the class name to get the input box and then use it

$(document).ready(function() {

    $(".InutClass").bind('keydown', function(e) {
        ....
    });

});

The above code will bind all the element which has InputClass , css class for the input field.

Asim Sajjad