Im trying to work out a quote value after a user makes a selection in 2 select boxes.
It looks like 1 need 2 switch statements. Is this possible? (There are a lot more possible values than the ones below. I've deleted them for the sake of clarity)
var workOutQuote = function() {
var value1 = $("#delivery_from_area").val();
var value2 = $("#delivery_to_area").val();
var val = '';
switch (value1)
{ case '1':
{ switch (value2)
{ case '1': val="90"; break; }
{ case '2': val="80"; break; }
{ case '3': val="70"; break; }
}
}
{ case '2':
{ switch (value2)
{ case '1': val="80"; break; }
{ case '2': val="90"; break; }
{ case '3': val="70"; break; }
}
}
}
Using the code above I get the error:
Uncaught SyntaxError: Unexpected token case
Use BREAK
, if you don't want to call all case
.
Otherwise ,you will get unexpected Results
var workOutQuote = function() {
var value1 = $("#delivery_from_area").val();
var value2 = $("#delivery_to_area").val();
var val = '';
switch (value1){
case '1':
switch (value2){
case '1': val="90"; break;
case '2': val="80"; break;
case '3': val="70"; break;
}
break;
case '2':
switch (value2){
case '1': val="80"; break;
case '2': val="90"; break;
case '3': val="70"; break;
}
break;
}
You are putting case in braces
, an example from your code { case '1': val="90"; break; }
var value1 = '2';
var value2 = '2';
var val = '';
switch (value1) {
case '1':
{
switch (value2) {
case '1':
val = "90";
break;
case '2':
val = "80";
break;
case '3':
val = "70";
break;
}
}
case '2':
{
switch (value2) {
case '1':
val = "80";
break;
case '2':
val = "90";
break;
case '3':
val = "70";
break;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With