SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I asked this question in the main SOF forum but I think it belongs here.

I need to add a little JavaScript to run when user clicks "Save and Close". I know in SharePoint 2010 I could just use PreSaveAction() but I am using 2003.


user clicks save and close
if attachment exists
  add the list entry
  alert the user to upload attachment

It looks like the function ClickOnce() is what triggers the form to save since the button href="javascript:ClickOnce()". So what I did was change the href of this link to my own function unless attachment exists. This did not work because it would either do nothing or fire when the page loaded whether there was an attachment or not.

Anyone have a workaround for this?

share|improve this question
up vote 0 down vote accepted

You could use jQuery to change the HREF on the save button to first call your javascript and then call the ClickOnce() function.

Something like:

share|improve this answer
This didnt work either. I think SharePoint javascript is running after mine and overwriting the href. – SystemAccount May 2 '12 at 17:56
Use a JavaScript timeout to set your HREF 200-300 MS after the page loads. That should give it enough time for SharePoint to do its thing, but quick enough that the user won't click the button before then. – John Chapman May 2 '12 at 19:02
The timeout made it work. – SystemAccount May 4 '12 at 13:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.