?
Solved

combine jquery scripts

Posted on 2012-03-28
6
Medium Priority
?
825 Views
Last Modified: 2012-08-13
I would like to combine the following scripts into one in a sharepoint Content Editor web part - when I attempt to do so, they are not running at all. would appreciate your assistance

<script src="/Style%20Library/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="/Style%20Library/js/jquery/jquery.spservices-0.5.8.min.js" type="text/javascript"></script>
<script type="text/javascript">
     jQuery(document).ready(function() {
          var User = $().SPServices.SPGetCurrentUser({
           fieldName: "Title",
           debug: false
      })

    //alert(User)
    return User;
//      $("div[Title='Requested By']", this).html(User);
//      $("textarea[title='Requested By']", this).val(User);
    $("input[Title='Author']").val(User);   
});
 function PreSaveAction() {
 
         var atch = document.getElementById("idAttachmentsTable");
          if (atch == null || atch.rows.length == 0)
 {
              document.getElementById("idAttachmentsRow").style.display='none';
 
alert("The Candidate's resume is required. Please attach the document.");
 return false ;
 }
 else { return true ;}
 }
 </script>

Open in new window


add this

<Script type="text/javascript"> 
function PreSaveAction() 
{ 
var attachment; 
var filename=""; 
var fileNameSpecialCharacters = new RegExp("[~#%&*{}<>;?/+|\"]"); 
try { 
attachment = document.getElementById("idAttachmentsTable").getElementsByTagName("span")[0].firstChild; 
filename = attachment.data; 
} 
catch (e) { 
} 
if (fileNameSpecialCharacters.test(filename)) { 
alert("Please remove the special characters from the file attachment name.");
return false; 
} 
else { 
return true; 
} 
} 
</script>

Open in new window

0
Comment
Question by:sullisnyc44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37780408
Only the very first script can be considered to be jQuery.

Here is what I came up with

<script src="/Style%20Library/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="/Style%20Library/js/jquery/jquery.spservices-0.5.8.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
  var User = $().SPServices.SPGetCurrentUser({
    fieldName: "Title",
    debug: false
  })
  $("input[Title='Author']").val(User);   
});

function PreSaveAction() {

  var attachment, 
        filename="", 
        fileNameSpecialCharacters = new RegExp("[~#%&*{}<>;?/+|\"]"); 

  var atch = $("#idAttachmentsTable");
  if (!atch || atch.length == 0)  {
    $("idAttachmentsRow").hide();
    alert("The Candidate's resume is required. Please attach the document.");
    return false ;
  }

  try { 
    attachment = $("idAttachmentsTable").find("span:eq(0)").html(); 
    filename = attachment.data; 
  } 
  catch (e) {} 
  if (fileNameSpecialCharacters.test(filename)) { 
    alert("Please remove the special characters from the file attachment name.");
    return false; 
  } 

  return true;
}
</script>

Open in new window

0
 

Author Comment

by:sullisnyc44
ID: 37782619
this does not work for me. I just want to add the functionality of the 2nd script to my first, working script.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37783692
Does not work how? Error messages? Anything in the console?
I am flying blind here since I only was given the script and not the table or span containing file name or such. And you had TWO scripts with the same name

Please provide more information.
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Accepted Solution

by:
sullisnyc44 earned 0 total points
ID: 37787838
so sorry - it's a content editor web part within sharepoint 2007.

I'm afraid I do not get an error - but I do not get prompted to attach a file or choose a better filename.

here is some more info:
http://sharepointchic.blogspot.com/2010/12/input-validation-for-file-attachment.html
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37788059
Can you post the view-source of the part that you test?
You can remove proprietary data and change field names if you need
0
 

Author Closing Comment

by:sullisnyc44
ID: 37875058
only my solution works
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question