PDA

View Full Version : Else if Statment help



rambo_jr
02-29-2012, 08:57 PM
coming from C++ back ground and new going into Java Script

i cant really seem to get the if Else statement working

What i am trying to do is put a error alert box in if any one types in anything over 100 it should show that but whats happening is if i type in 600 its showing the Error Box but also saying you got an A+ after i click ok on the Error Box..

the else i showing an Error i cant seem to figure how can i get this part working





script type='text/javascript'>
function show(which) {
var mark = parseInt(which.value,10) || 0;

if (mark >100)
which.value = mark;
alert("Please Enter between 0 & 100 !");

else

if (mark <100)
var mod = which.id;
var grade = "Failed";
if (mark >=40) {grade = "D"}
if (mark >=60) {grade = "C"}
if (mark >=78) {grade = "B"}
if (mark >=85) {grade = "A"}
if (mark >=93) {grade = "A+"}
alert ("Your grade for " + mod + " is " + grade);
}
</script>

rambo_jr
02-29-2012, 09:07 PM
got it working i just messed around with the { }


i have 4 text boxes how can i get a image if all 4 boxes have has a value more then 40

else if all but one have a value less then 40 show a different image ?



<script type='text/javascript'>
function show(which) {
var mark = parseInt(which.value,10) || 0; // trap non-numeric entries, make number integer
if (mark >100) {
alert("Please Enter between 0 & 100 !");
which.value = mark; } // write it back to the field

else if (mark <=100){
var mod = which.id;
var grade = "Failed";
if (mark >=40) {grade = "D"}
if (mark >=60) {grade = "C"}
if (mark >=78) {grade = "B"}
if (mark >=85) {grade = "A"}
if (mark >=93) {grade = "A+"}
alert ("Your grade for " + mod + " is " + grade);
}
}
</script>