user1759124
user1759124

Reputation: 3

Validate form before calculating

I have a calculation form with the following code

$("input[name^=sum]").keyup(function(){
    $('#result').text(Math.round(($('#amount').val() * 13 * 1.5 ) / ( (52 - $('#weeks').val()) * $('#hours').val() ) ));
});

I'm trying to validate that all 3 inputs are always filled before executing the calculation, like so

$("form input[name^=sum]").blur(function()
if( !$(this).val() ) {

  }
else  {
    $('#result').text(Math.round(($('#amount').val() * 13 * 1.5 ) / ( (52 - $('#weeks').val()) * $('#hours').val() ) ));
}
});

This only works per individual input, not as a form.

What am I doing wrong here?

Upvotes: 0

Views: 110

Answers (1)

Sivagopal Manpragada
Sivagopal Manpragada

Reputation: 1634

try this

if($(#input1).val()!="" && $(#input1).val()!="" && $(#input1).val()!="")
{
      your caluculation
}

Upvotes: 1

Related Questions