1

The following code runs fine from the #input-lines-percent inputs and updates the values correctly. #input-curves-percent does run the code so the change seems to be working, but it's not updating the text boxes at all.

To see what I mean, type some text in the Straight lines % box and see how both text boxes update. However try this on the Curves % and there is no update. The code for both is almost identical, so I am not sure what is causing this difference.

$('#input-curves-percent').change(function(e){
    updatePercentGroupShape('curve');
});
$('#input-lines-percent').change(function(e){
    updatePercentGroupShape('line');
});
function updatePercentGroupShape(lastEdit){
    // Updates the percentage boxes for the shape type percents
    
    var curves = parseInt($('#input-curves-percent').val());
    var lines = parseInt($('#input-lines-percent').val());

    if(lastEdit.localeCompare('curve') == 0){
        
        if(curves < 0){
            curves == 0;
        }else if(curves > 100){
            curves = 100;
        }
        lines = 100 - curves;

    }
    if(lastEdit.localeCompare('line') == 0){
        
        if(lines < 0){
            lines == 0;
        }else if(lines > 100){
            lines = 100;
        }
        curves = 100 - lines;
    }
    $('#input-curves-percent').val(curves);
    $('#input-line-percent').val(lines);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
	<div>Curves %</div>
	<div><input type="text" id="input-curves-percent" value="0"></div>
</div>
<div>
	<div>Straight lines %</div>
	<div><input type="text" id="input-lines-percent" value="100"></div>
</div>

1
  • what is that lastEdit.localeCompare('curve') is doing? Commented Jul 15, 2015 at 7:41

2 Answers 2

3

There's a typo in last js line, just replace

    $('#input-line-percent').val(lines);
                 ^^^

with

    $('#input-lines-percent').val(lines);
Sign up to request clarification or add additional context in comments.

Comments

2

There was a typo error in it.

 id="input-lines-percent"

and in script

$('#input-line-percent').val(lines);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.