Solved

combine jquery scripts

Posted on 2012-03-28
6
796 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

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.

Question has a verified solution.

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

Suggested Solutions

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

772 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