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

  • Home
  • SEARCH
  • 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 7604233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:51:31+00:00 2026-05-30T23:51:31+00:00

I have 4 input fields that when numbers are entered into one of the

  • 0

I have 4 input fields that when numbers are entered into one of the first 3 using jquery .keyup, they are totaled and added into the fourth. I also have a series of if else statements that run when a .keyup is entered into the fourth, they determine the value of the .keyup and draw a certain number of paths (bottles) to the raphael paper.

What I am wanting to do is when one of the first three values is entered I want the total of the fourth to be passed to the if else statments and decide how many paths (bottles) to be drawn to the raphael paper. Instead of having to type directly into the fourth input.

It seems that .keyup wont work for this unless the cursor is in the input field. What is another way to grab info from a input field that is being generated by a .text? is basically what I am looking for.

Hopefully this makes sense.

http://jsfiddle.net/anderskitson/QX9C7/

$('#the_input_id').keyup(function() {
    updateTotal();
});

$('#the_input_id1').keyup(function() {
    updateTotal();
});

$('#the_input_id2').keyup(function() {
    updateTotal();
});

var updateTotal = function() {
    var input1 = parseInt($('#the_input_id').val());
    var input2 = parseInt($('#the_input_id1').val());
    var input3 = parseInt($('#the_input_id2').val());
    if (isNaN(input1) || isNaN(input2) || isNaN(input3)) {
        $('#total').text('');
    } else {
        var max = 300;
        var total = input1 + (input2 * 2) + (input3 * 3);

        if (total > max) {
            $('#total').text('The maximum is ' + max);
            $('#total1').val(500);
        } else {

            $('#total1').val(total);
        }


    }
};
var default_val = '';
$('input[class^="class-"]').focus(function() {
    if ($(this).val() == $(this).data('default_val') || !$(this).data('default_val')) {
        $(this).data('default_val', $(this).val());
        $(this).val('');
    }
});

$('input[class^="class-"]').blur(function() {
    if ($(this).val() == '') {
        $(this).val($(this).data('default_val'));
    }
});

var paper = Raphael(document.getElementById("notepad"), 400, 70);

function drawBottles(count) {
    for (i = 0; i < count; i++) {

        var randomNumber3 = Math.floor(Math.random() * 25);
        var path_a = paper.path("M242.07,270.119c0,0-14.596-30.606-7.625-35.793 c3.864-2.876,2.145-18.561,1.832-18.784c-0.313-0.224-1.839-0.319-1.839-0.319c-1.555-0.192-0.201-3.456-0.201-3.456 s0,0-0.598-0.352c-0.598-0.351,1.129-1.345,1.129-1.345c3.738-2.785,10.449-2.983,11.126-2.344c0.677,0.64-0.354,1.44-0.354,1.44 s0.73,0.832,1.333,2.111c0.604,1.28-0.792,1.665-0.792,1.665c1.852,6.718,9.877,14.935,9.877,14.935 c4.795,0.589,7.7,10.683,7.7,10.683l6.271,22.746C269.929,261.307,263.641,270.119,242.07,270.119z");
        path_a.attr({
            fill: 'none',
            stroke: '#231F20',
            "stroke-width": '3',
            "stroke-miterlimit": '10',
            'stroke-opacity': '1'
        }).data('id', 'path_a');
        path_a.translate((i * 30) - 225, -200);
        path_a.rotate(randomNumber3);

    } //end of for statement
}

$("#total1").keyup(function() {
    var val = $(this).val();
    if (val.length === 0) {
        paper.clear();
        $("#max").text('');
        return;
    }
    var value = parseInt(val);
    paper.clear();
    if (value > 300) {
        drawBottles(10);
        $("#max").text('you have reached the maximum');
    } else if (value > 270) {
        drawBottles(10);
    } else if (value > 240) {
        drawBottles(9);
    } else if (value > 210) {
        drawBottles(8);
    } else if (value > 180) {
        drawBottles(7);
    } else if (value > 150) {
        drawBottles(6);
    } else if (value > 120) {
        drawBottles(5);
    } else if (value > 90) {
        drawBottles(4);
    } else if (value > 60) {
        drawBottles(3);
    } else if (value > 30) {
        drawBottles(2);
    } else if (value != 0 && 0 != value.length) {
        drawBottles(1);
    }

});
  • 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-05-30T23:51:33+00:00Added an answer on May 30, 2026 at 11:51 pm

    Call keyup() on $('#total1') at the end of updateTotal:

    var updateTotal = function() {
        var input1 = parseInt($('#the_input_id').val());
        var input2 = parseInt($('#the_input_id1').val());
        var input3 = parseInt($('#the_input_id2').val());
        if (isNaN(input1) || isNaN(input2) || isNaN(input3)) {
            $('#total').text('');
        } else {
            var max = 300;
            var total = input1 + (input2 * 2) + (input3 * 3);
    
            if (total > max) {
                $('#total').text('The maximum is ' + max);
                $('#total1').val(500);
            } else {
    
                $('#total1').val(total);
            }
        }
    
        $('#total1').keyup();  // This will trigger the keyup handler.
    };
    

    This will call the keyup handler for the field programatically.

    Added to your jsfiddle here: http://jsfiddle.net/QX9C7/4/

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

Sidebar

Related Questions

I have a form that asks users to input numbers into multiple form fields.
I have a form that uses jquery to generate rows of input fields these
i have made an app that would calculate numbers from input fields. **main Activity
I have javascript function that automatically adds input fields together, but adding numbers like
I hope I can explain this right I have two input fields that require
I have a google map that takes and put coordinates from input fields .
I have a jQuery jPicker colorpicker that is bound to an input text field
I have one input fields with an autocomplete ( #street ) and one with
I have a form that contains two input textboxes, one called serial and the
I have an input field that is by default set to type=text so that

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.