Jump to content
Larry Ullman's Book Forums

Recommended Posts

// JavaScript Document
$(document).ready(function(){

//declare variables
    function calculate(){
    var weight, height, bmi;
    weight= $('#weight').val();
    height= $('#height').val();
    
  //calculate total
  bmi = weight*703/(height*height);
  bmi = bmi.toFixed(1);
 
  $('#bmi').val(bmi);
 
 
 
 
   if (bmi < 18.5){
     $('#bmi_message').html('Your BMI shows you are under weight.');
  }
 
  if (bmi >= 18.5 && bmi <= 24.9){
      $('#bmi_message').html('Your BMI shows you are a normal weight.');
  }
  if (bmi >= 25 && bmi <= 29.9){
      $('#bmi_message').html('Your BMI shows you are over weight.');
  }
   
     if (bmi > 30){
    $('#bmi_message').html('Your BMI show you are obese.');
  }
 


return false;

}//end of calculate function

    $('#bmiform').submit(calculate);
    $('#bmiform').validate({
        rules: {
        },
        messages:{
        height: "Please enter a valid height between 24 in. and 100 in.", weight: "Please enter a valid weight between 20 lb. and 500 1b."
    }
    
    });
    return false;
    
    
});


I am trying to get this so that it does not calculate unless the form is validated.  Not sure what I am doing wrong.

Share this post


Link to post
Share on other sites

What's the HTML form look like? What, if any, errors are you seeing? What is working? What isn't working? What's happening that shouldn't? What isn't happening that should? 

 

In short: give us more to go on here.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...