views:

44

answers:

4

Here's my ASP.NET form. When I click one button it calls both jQuery functions. It's probably a rudimentary HTML question but I'm not sure why:

<form id="form1" runat="server">
    <div id="testDialog">
    </div>

    <p><input type="button" id="invoke1" value="test 1" /></p>

    <input type="button" id="invoke2" value="test 2" />
</form>

<script type="text/javascript">
    $(function() {
        $("input:invoke1").click(function(){
            showSomething("testDialog");
        });

        $("input:invoke2").click(function(){
            showSomething2("test.aspx", options);
        });
    });
</script>
+3  A: 

shouldnt those selectors be

$("input#invoke1") and  $("input#invoke2")
mkoryak
if that's the case then why did : work in terms of getting an event to fire and both functions to run? Probably you're right, the .click was happening for anything clicked because it was not properly referencing the buttons so when I clicked anything, both click events ran.
CoffeeAddict
so then I guess when would you use :, I thought I saw this in one of my jQuery books..input: I forget where I got this idea from.
CoffeeAddict
A: 

try just

 $("#invoke1").click(function(){
        showSomething("testDialog");
    });

    $("#invoke2").click(function(){
        showSomething2("test.aspx", options);
    });

since id's should be unique, this should solve your problem

phi
A: 

You could even try

$("#invoke1")... and  $("#invoke2")...
Daniel Dyson
A: 

the ID is unique for the document I see no need to include input with it, as follows

$("#invoke1").click()
$("#invoke2").click()
Kronass