Changed PHP code to JS code