I have a SharePoint 2013 Online site. On a form page, I am trying to use the CEWP to run JavaScript to allow me to pre-fill in a form field and then disable it.
I have found numerous sites which have code to make this happen. However, even though I follow their steps I cannot get this to work. I can't even tell if the JavaScript is firing off or if it is sitting dormant.
Are there any settings which I should check which would prevent me from using the CEWP to run JavaScript?
How can I check if my scripts have ran?
Below is the script I'm trying to execute from a file titled newChild.js
<!--
Name: newChild.js
-->
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
//get the Issue ID from they query string
var customerID = getParameterByName("CustID");
//Set the corresponding Lookup field value to the Issue ID
$("select[title='External Contact']").val(customerID);
//use this line to disable the lookup field selection
$("select[title='External Contact']").attr('disabled','disabled')
//use this line to hide the lookup field and label entirely
//$("select[title='External Contact']").closest("tr").hide();
});
// no, I didn't write this function from scratch, I found it at
// http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
function getParameterByName(name)
{
name = name.replace(/[[]/, "\[").replace(/[]]/, "\]");
var regexS = "[\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/+/g, " "));
}
</script>
debuggerkeyword in JavaScript to test if it executes. It will trigger debugger breakpoint if you have developer tools open in your browser.alert("hi");before thevar customerID...line. If this code is in a file named thisChild.js, where is this file located? Are you therefore only linking to this JS file in your CEWP? Please share what you're putting into your CEWP.