updated javascript for cleaner input logic