1

I have a generic out of box web part page. I have added a content editor web part on that page that links to a HTML file because I want to build my own custom form via HTML.

Here is the HTML file.

<!DOCTYPE html>
<style>
    .field{
        padding: 4px;
        margin: 1px;
    }
    .field label{
        display: inline-block;
        width: 160px;
        margin-left: 5px;
    }
    .field select{
        display: inline-block;
    }
</style>
<html>
<head>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>

    <script>
        $(document).ready(function(){
            $("#ItemTypeSelect").append(new Option('test', 'test'));
        });
    </script>
</head>

<body>
    <div class="field">
        <label>Item Type:</label>
        <select id="ItemTypeSelect" name="ItemType"></select>
    </div>
    <div class="field">
        <label>Manufacturer:</label>
        <select name="Manufacturer"></select>
    </div>
    <div class="field">
        <label>Model:</label>
        <select name="Model"></select>
    </div>
    <div class="field">
        <label>Serial Number(s):</label>
        <select multiple='multiple' name="SerialNumber"></select>
    </div>
</body>


</html>

On page load, my scripts are not working, and I'm not receiving any runtime errors in the console. I have also tried adding a script editor to my page and put the scripts that you see above in the script editor and they are still not working without any errors in console.

How do I get scripts to work in an HTML file or script editor for a form inside a content editor?

1
  • Try adding breakpoint inside document.ready() and debug. See if gets the select element properly. Jan 8, 2019 at 15:52

2 Answers 2

2

You need to add type attribute to your script tag, like given below:

<script type="text/javascript">console.log('In.');</script>
0

just in case this helps anyone I also had to call use .js extension instead of .html on the linked file to get the scripts to load

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jul 7 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.