Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. How to write the handler for buttons using JQUERY

How to write the handler for buttons using JQUERY

Scheduled Pinned Locked Moved JavaScript
javascripthtmlcsstutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Can Work
    wrote on last edited by
    #1

    Hello! )) I try to write handler for buttons in JS through CSS-selectors. But i meet with difficulties. in case of links this code JQuery works fine:

    $(document).ready(function() { // waiting for page loading
    var steps = $("form").children(".step"); // find all steps of the form
    $(steps[0]).show(); // show 1st step
    var current_step = 0; // set the current step
    $("a.next").click(function(){ // Event of link-click "necxt step"
    if (current_step == steps.length-2) { // checking - will it the next step is last
    $(this).hide(); // i hide the link "next step"
    $("form input[type=submit]").show(); // show thge button "OK"
    }
    $("a.back").show(); // show the link "Back"
    current_step++; // increase the counter of the current slide
    changeStep(current_step); // change a step
    });

    $("a.back").click(function(){ // Click event on a small window

    if (current_step == 1) { // checking - will it the next step is last
    $(this).hide(); // hide the link "back"
    }

    $("form input[type=submit]").hide(); // hide the button "OK"

    $("a.next").show(); //hide the link "Next step"

    current_step--; // increase the counter of the current slide

    changeStep(current_step);// change a step

    });

    function changeStep(i) { // the function of step changing

    $(steps).hide(); // hide all steps

    $(steps[i]).show(); // show the current

    }

    });

    But i'd rather to prefer make this fuctionality for buttons - "Next" and "Back" My HTML-code

    Page

    step 1

    Name:

    step 2

    Sourname:

    step 3

    E-mail:

    Z J M 3 Replies Last reply
    0
    • A Alex Can Work

      Hello! )) I try to write handler for buttons in JS through CSS-selectors. But i meet with difficulties. in case of links this code JQuery works fine:

      $(document).ready(function() { // waiting for page loading
      var steps = $("form").children(".step"); // find all steps of the form
      $(steps[0]).show(); // show 1st step
      var current_step = 0; // set the current step
      $("a.next").click(function(){ // Event of link-click "necxt step"
      if (current_step == steps.length-2) { // checking - will it the next step is last
      $(this).hide(); // i hide the link "next step"
      $("form input[type=submit]").show(); // show thge button "OK"
      }
      $("a.back").show(); // show the link "Back"
      current_step++; // increase the counter of the current slide
      changeStep(current_step); // change a step
      });

      $("a.back").click(function(){ // Click event on a small window

      if (current_step == 1) { // checking - will it the next step is last
      $(this).hide(); // hide the link "back"
      }

      $("form input[type=submit]").hide(); // hide the button "OK"

      $("a.next").show(); //hide the link "Next step"

      current_step--; // increase the counter of the current slide

      changeStep(current_step);// change a step

      });

      function changeStep(i) { // the function of step changing

      $(steps).hide(); // hide all steps

      $(steps[i]).show(); // show the current

      }

      });

      But i'd rather to prefer make this fuctionality for buttons - "Next" and "Back" My HTML-code

      Page

      step 1

      Name:

      step 2

      Sourname:

      step 3

      E-mail:

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      I do not understand what you are asking.

      There are two kinds of people in the world: those who can extrapolate from incomplete data. There are only 10 types of people in the world, those who understand binary and those who don't.

      1 Reply Last reply
      0
      • A Alex Can Work

        Hello! )) I try to write handler for buttons in JS through CSS-selectors. But i meet with difficulties. in case of links this code JQuery works fine:

        $(document).ready(function() { // waiting for page loading
        var steps = $("form").children(".step"); // find all steps of the form
        $(steps[0]).show(); // show 1st step
        var current_step = 0; // set the current step
        $("a.next").click(function(){ // Event of link-click "necxt step"
        if (current_step == steps.length-2) { // checking - will it the next step is last
        $(this).hide(); // i hide the link "next step"
        $("form input[type=submit]").show(); // show thge button "OK"
        }
        $("a.back").show(); // show the link "Back"
        current_step++; // increase the counter of the current slide
        changeStep(current_step); // change a step
        });

        $("a.back").click(function(){ // Click event on a small window

        if (current_step == 1) { // checking - will it the next step is last
        $(this).hide(); // hide the link "back"
        }

        $("form input[type=submit]").hide(); // hide the button "OK"

        $("a.next").show(); //hide the link "Next step"

        current_step--; // increase the counter of the current slide

        changeStep(current_step);// change a step

        });

        function changeStep(i) { // the function of step changing

        $(steps).hide(); // hide all steps

        $(steps[i]).show(); // show the current

        }

        });

        But i'd rather to prefer make this fuctionality for buttons - "Next" and "Back" My HTML-code

        Page

        step 1

        Name:

        step 2

        Sourname:

        step 3

        E-mail:

        J Offline
        J Offline
        John C Rayan
        wrote on last edited by
        #3

        If you want to use button in place of link , then you have to use id of the button and use .click handler. For instance, you have a button like this

        Next

        then your click handler could be $('#btnNext').click (.....

        1 Reply Last reply
        0
        • A Alex Can Work

          Hello! )) I try to write handler for buttons in JS through CSS-selectors. But i meet with difficulties. in case of links this code JQuery works fine:

          $(document).ready(function() { // waiting for page loading
          var steps = $("form").children(".step"); // find all steps of the form
          $(steps[0]).show(); // show 1st step
          var current_step = 0; // set the current step
          $("a.next").click(function(){ // Event of link-click "necxt step"
          if (current_step == steps.length-2) { // checking - will it the next step is last
          $(this).hide(); // i hide the link "next step"
          $("form input[type=submit]").show(); // show thge button "OK"
          }
          $("a.back").show(); // show the link "Back"
          current_step++; // increase the counter of the current slide
          changeStep(current_step); // change a step
          });

          $("a.back").click(function(){ // Click event on a small window

          if (current_step == 1) { // checking - will it the next step is last
          $(this).hide(); // hide the link "back"
          }

          $("form input[type=submit]").hide(); // hide the button "OK"

          $("a.next").show(); //hide the link "Next step"

          current_step--; // increase the counter of the current slide

          changeStep(current_step);// change a step

          });

          function changeStep(i) { // the function of step changing

          $(steps).hide(); // hide all steps

          $(steps[i]).show(); // show the current

          }

          });

          But i'd rather to prefer make this fuctionality for buttons - "Next" and "Back" My HTML-code

          Page

          step 1

          Name:

          step 2

          Sourname:

          step 3

          E-mail:

          M Offline
          M Offline
          Member 10697386
          wrote on last edited by
          #4

          you want to use your input button in place of link , then you can use id of the input button and use .click handler. Use HTML instance

          of this

          and Script

          $("#btnNext").click(function () { // Event of link-click "necxt step"
          if (current_step == steps.length - 2) { // checking - will it the next step is last
          $(this).hide(); // i hide the link "next step"
          $("form input[type=submit]").show(); // show thge button "OK"
          }
          $("a.back").show(); // show the link "Back"
          current_step++; // increase the counter of the current slide
          changeStep(current_step); // change a step
          });

          do same as it is for another button

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups