This works with a return statement. There is a problem in using the onclick handler and leaving a document.write statement inside the function. YOU CANNOT DO THAT with this event handler. The document.write inside the function cuts the script off when it trys to do the write so that the program cannot return the value and finish the function.