Click to See Complete Forum and Search --> : batch ifs? Newbie Q


freaksarise
05-12-2003, 07:01 PM
Hello everyone.
The following works as follows:

User clicks radio buttons. Value from radio buttons are "collected" from markPoint function OnClick.

function markPoint(pointValue) {
alert (pointValue)
}

I would like to test the value of "pointValue" so that the logic is like this:

If "pointValue" == "everyday" ...
If "pointValue" == "twice_week" ...
If "pointValue" == "once_week" ...
If "pointValue" == "never" ...

What is a quick way to do this?
Using "case"? A loop?
Thanks
FA

Sorry I know this is real simple stuff.

freaksarise
05-12-2003, 07:45 PM
function markPoint(pointValue) {
alert (pointValue)

switch (pointValue) {

case "everyday":
test = 5;
break;

case "twice_week":
test = 4;
break;

case "once_week":
test = 3;
break;

case "once_month":
test = 2;
break;
}
alert (test)
}

Charles
05-13-2003, 05:37 AM
If you are just assigning a variable depending upon some value then using an object is the quickest way, and using an anonymous object takes the least typing.

<script type="text/javascript">
<!--
pointValue = 'once_week';
alert ({everyday : 5, twice_week : 4, once_week : 3, once_month : 2, never : 0}[pointValue]);
// -->
</script>