1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Invoke JS function when "Create Thread" button is clicked?

Discussion in 'General PHP and MySQL Discussions' started by Kevin, Jun 16, 2014.

  1. Kevin

    Kevin Well-Known Member

    I'm working on a minor tweak to an add-on and, as part of it, I would like to invoke a javascript function with the "Create Thread" button is clicked.

    I've tried going down the path of using jQuery but ran into a bit of a stumbling block because the "Create Thread" buttons don't have ID values assigned to them ("them" because there are two on the page when creating a thread).

    My real goal is to change the value of a text box after clicking the "Create Thread" button and before the form post kicks in but to keep it simple I'm starting with just generating a standard JS alert message for testing.

    With that it mind... what approach would you take to invoke a JS function when clicking on the "Create Thread" button?

    Just to be clear, if you were at http://xenforo.com/community/forums/test-messages.6/create-thread and clicked either of the "Create Thread" buttons, how would you go go about displaying a JS alert message when the button is clicked?
     
  2. euantor

    euantor Well-Known Member

    Try this to select the button in jQuery:

    Code:
    $(".thread_create input[type='submit']").click(function(e) {
        // Event handler goes here...
    });
    
     
    Kevin likes this.
  3. Kevin

    Kevin Well-Known Member

    {Does a quick test....} Yes! Exactly what I was after, thank you. :cool:
     
    euantor likes this.

Share This Page