Solved

combine jquery scripts

Posted on 2012-03-28
6
783 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now