I deleted cause I didn't want to get involved with this, but you caught me. It's like having two or more ID's with the same name. The browser don't now which one. The $(document).ready(function() is where the browser goes after the page loads, yours don't know where to go. (simplified)
You have a number of errors in your coding. Putting your js/jq together will help you find them.
Since things 'refresh', I'd say it's in the js/jq code and not the php. But your php has errors in writing the html. At lest that's what my editor says.
Sorry I couldn't be more help. Clean up the code and see what happens.
There is always http://validator.w3.org/