updated javascript code to include form processing