Using javascript to handle context selection