Solved

combine jquery scripts

Posted on 2012-03-28
6
790 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

930 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

9 Experts available now in Live!

Get 1:1 Help Now