Andy Howard
Andy Howard

Reputation: 41

live validation issue

i have created a form with some input type=""text" boxes that calculates a total into another input box.

I would like to use this live validation (website) to check that the 11th box doesnt go over a set amount. the problem is that the third box is a read only box so it doesnt register the change give by the other two boxes, unless you click on the box thats being changed.

Is there anyway of doing this with clicking on it to change it Heres the code i'm working on

<form onsubmit="return false;" id="frmCreateCheckboxRange" method="post" action="">
<fieldset>
    <legend>Calculation Examples</legend>
    <div id="formContent">

        <p id="ex-sum">
            The Calculation plug-in can parse various DOM elements. From normal
            <code>div</code> and <code>span</code> tags to all form field elements.
        </p>

        <p>
            Numbers:

            <input type="text" size="2" value="0" name="sum_1">
            <input type="text" size="2" value="0" name="sum_2">
            <input type="text" size="2" value="0" name="sum_3">             
            <input type="text" size="2" value="0" name="sum_4">
            <input type="text" size="2" value="0" name="sum_5">
            <input type="text" size="2" value="0" name="sum_6">
            <input type="text" size="2" value="0" name="sum_7">
            <input type="text" size="2" value="0" name="sum_8">
            <input type="text" size="2" value="0" name="sum_9">
            <input type="text" size="2" value="0" name="sum_10" id="sum_10">
            &nbsp;&nbsp;
            Sum:
            <input type="text" readonly="readonly"  size="2" value="" id="totalSum" name="totalSum">

            <script type="text/javascript">
        var totalSum = new LiveValidation('totalSum');
        totalSum.add(Validate.Numericality, { maximum: 10 } );
      </script>  
            (Change the values for dynamic calculations.)



        </p>


</fieldset>

heres the link to the project itself

thanks to anyone who can help, hope I made sense

Upvotes: 0

Views: 320

Answers (1)

adeneo
adeneo

Reputation: 318302

The third box does not look like it's read only, so I'll assume you meant the elevententh box?

There is no calculation done, so I added one, and I do not for the life of me understand why you would need a validation plugin to check if the total of the calculations you are doing is above a certain value ?

$(function() {
    $('input[name^="sum_"]').on('change keyup', function() {
        var value = 0,
            max = 100; //set a max value
        $('input[name^="sum_"]').each(function() {
            value += parseInt(this.value, 10);
        });
        if (value < max) $("#totalSum").val(value); //check if over max value
    });
}​);​

FIDDLE

Upvotes: 1

Related Questions