Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

http://stackoverflow.com/questions/10415929/sharepoint-2003-presaveaction

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.

Pseudo:

user clicks save and close
if attachment exists
  add the list entry
else 
  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
add comment

1 Answer

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:

href="javascript:YourFunction();ClickOnce();"
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
add comment

Your Answer

 
discard

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.