moving the action call into the if statement

the javascript was getting run on admin pages