either return variable to global or if/else statement
I have searched everywhere for a simple solutions to my problem, but can't seem to find it.
I have a form with a drop down box and then multiple text options after that.
The drop down box take the value and runs through a switch statement assigning values that are then plugged into the rest of the text boxes.
The problem I am having is being able to change the value of each of those text boxes, independent of the drop down values.
$(function() {
$("#soiltype").change(function(){
var soiltype=$("#soiltype").val();
switch (soiltype)
{
case 'finesand':
soiltype=0.05;
mad=60;
break;
case 'loamysand':
soiltype=0.07;
mad=60;
break;
case 'sandyloam':
soiltype=.11;
mad=50;
break;
case 'loam':
soiltype=0.15;
mad=50;
break;
case 'siltyloam':
soiltype=.2;
mad=50;
break;
case 'silt':
soiltype=.2;
mad=50;
break;
case 'sandyclayloam':
soiltype=.11;
mad=50;
break;
case 'clayloam':
soiltype=.16;
mad=50;
break;
case 'siltyclayloam':
soiltype=.18;
mad=50;
break;
case 'sandyclay':
soiltype=.12;
mad=50;
break;
case 'siltyclay':
soiltype=.15;
mad=40;
break;
case 'clay':
soiltype=.14;
mad=30;
break;
}
$("#alloweddepl").val(mad);
mad=mad/100;
var root=$("#rootdepth").val();
irrigamount=root*soiltype*mad;
IrrAmt=$("#IrrAmt").val(irrigamount);
});
//Need to detect a change in all the other variables and run them through the irrigation amount equation, and then reassign the IrrAmt.
});
I hope this make sense, and yes i know the code to detect a change in the other variables is missing. I'm not sure how to include them in this code. In the end. I need to be able to take the values from the root (if changed) and even mad (if changed) and rerun that IrrAmt equation.
Any ideas would be appreciated