?
Solved

combine jquery scripts

Posted on 2012-03-28
6
Medium Priority
?
837 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
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

830 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