Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:19:27+00:00 2026-06-03T00:19:27+00:00

I have simple code to increment and decrement field. everything was fine but i

  • 0

I have simple
code to increment and decrement field. everything was fine but i don’t know how many field I get ( it’s generate by mvc) My question is how to smart bind two buttons for each field on page?
I tried to use $(this.id+"x").val(currentVal - 1) but it’s wrong way , I think.

Thanks for any suggestions

Additional:

  1. I can’t use Jquery Mobile range input.
  2. Text box “Text Pin #4” must be allways focused.
  3. All buttons must be possible to click on Mobile device.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:19:28+00:00Added an answer on June 3, 2026 at 12:19 am

    You can select elements relative to the one that has the event triggered on it:

    $(".bplus").click(function() {
    
        //find the input relative to this element
        $(this).closest('td').prev().children('input').val(function (i, oldValue) {
    
            //make sure the old value is being interpreted as an integer
            oldValue = parseInt(oldValue, 10);
    
            //if the old value is a valid integer below 999 then add one,
            //otherwise return 999
            return (oldValue != NaN && oldValue < 999) ? (oldValue + 1) : 999;
        });
    });
    
    $(".bminus").click(function() {
    
        //find the input relative to this element
        $(this).closest('td').next().children('input').val(function (i, oldValue) {
    
            //make sure the old value is being interpreted as an integer
            oldValue = parseInt(oldValue, 10);
    
            //if the old value is a valid integer above 0 then subtract one,
            //otherwise return 0
            return (oldValue != NaN && oldValue > 0) ? (oldValue - 1) : 0;
        });
    });
    

    Here is a demo: http://jsfiddle.net/uSzr7/16/

    Here is some documentation for ya:

    • .closest(): http://api.jquery.com/closest
    • .prev(): http://api.jquery.com/prev
    • .children(): http://api.jquery.com/children
    • .val(): http://api.jquery.com/val (see the section on passing .val() a function)

    Another way to handle the validation is to always add or subtract one but then add a change event handler to the input elements that checks to make sure the value is valid. This helps work with native form controls since you are using the type="number" input tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code but I can't figure for the life of me
i have this simple code to load data from other php page using get
Uh..... I have no idea why this simple code snippet isn't working: function increment()
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have this simple code to count punctuation in a string. ie there's 2
I have a simple code that is supposed to do one task, when the
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I have a simple code byte[] buffer = Encoding.UTF8.GetBytes(abracadabra); MemoryStream ms = new MemoryStream();
I have a simple code fragment in JS working with prototype inheritance. function object(o)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.