#1
ID's must be unique.
In MooTools you can do $('roomtype')
to get the element with the ID roomtype
.
You can also use document.id('roomtype')
or even $$('#roomtype')
.
Since ID's must be unique it's irrelevant the parent of that element, because there is only one.
#2
Note that $
and $$
are different element methods in mootools. $$
takes a CSS selector and returns a collection/array.
$$('#roomtype').get('value'); // returns ['the value']
$('roomtype').get('value'); // return 'the value'
#3
The other problem I see is that you define the price inside the scope of updatePrice()
function, so doing price = 5000
inside the switch will not leave the function's scope anyway. You might want to define the var price outside the function, or make the function return that value lie this:
// ...
switch (room) {
case "AirCon":
price = "10000";
alert("AirCon");
break;
case 'Dorm':
price = "5000";
alert("Dorm");
break;
default:
price = "00";
}
return price; // here
}
If you update your fiddle with HTML it will be easier to help you more.
P.s: You are always welcome to ask questions. No need to feel embarrassed.