I have recently created a add-in for SharePoint online that will allow me to make a subsite. My written code doesn't show any errors, but it seems like it won't execute after a button click.

    <script type="text/javascript">
    $(function () {

    function bindButtonClick() {
        $("Submit").on("click", function () {
            var name = $("Naam").val(); // var name = Titel van de subsite
            var description = $("Omschrijving").val(); // var description = Omschrijving van de subsite
            if (name == '' || description == '') {
                alert("Vul eerst alle velden in.");
            else {

    function createSite() {
        // Eerst de variabelen opzetten
        var siteTitle = $("Naam").val(); 
        var siteDesc = $("Omschrijving").val(); 
        var siteUrl = $("URLInput").val();

        //  Omgevingsinfo opslaan in variabelen
        var clientContext = new SP.ClientContext('https://orgname.sharepoint.com/sites/addin-development');
        var collWeb = clientContext.get_web().get_webs();
        var webCreationInfo = new SP.WebCreationInformation();

        // webCreationInfo invoeren
        webCreationInfo.set_language(1043); // id=1043 voor nederlands, id=1033 voor engels. Meer id's hier:https://goo.gl/2YCAyo

        // webCreationInfo opslaan en site-aanmaakquery uitvoeren
        var oNewWebsite = collWeb.add(webCreationInfo);
            Function.CreateDelegate(this, this.onQuerySucceeded),
            Function.createDelegate(this, this.onQueryFailed)

    function onQuerySucceeded() {
        alert("De site is met succes aangemaakt!");

    function onQueryFailed(sender, args) {
        alert('Request failed.' + args.get_message() + '\n' + args.get_stackTrace());

    <p id="message">
        <!-- The following content will be replaced with the user name when you run the app - see App.js -->

<asp:Label ID="Naam" runat="server" Text="Label">Voer hier de naam van de site in</asp:Label>
<asp:TextBox ID="NaamInput" runat="server"></asp:TextBox> <!-- site title -->

<asp:Label ID="URL" runat="server" Text="Label">Voer hier de naam(url) van de site in</asp:Label>
<asp:Label ID="URLDescr" runat="server" Text="Label">https://orgname.sharepoint.com/sites/addin-development/</asp:Label>
<asp:TextBox ID="URLInput" runat="server"></asp:TextBox> <!-- site url -->

<asp:Label ID="Projector" runat="server" Text="Label">Voer hier de naam van de projector in</asp:Label>
<asp:TextBox ID="ProjectorInput" runat="server"></asp:TextBox>

<asp:Label ID="KlantNaam" runat="server" Text="Label">Voer hier de naam van de klant in</asp:Label>
<asp:TextBox ID="KlantNaamInput" runat="server"></asp:TextBox>

<asp:Label ID="Omschrijving" runat="server" Text="Label">Voer hier de omschrijving van de site in</asp:Label>
<asp:TextBox ID="OmschrijvingInput" runat="server"></asp:TextBox> <!-- site description -->

<asp:Label ID="Logo" runat="server" Text="Label">Upload hier het logo van de site</asp:Label>
<asp:FileUpload ID="LogoInput" runat="server" /> <!-- site logo -->

<asp:Button ID="Submit" runat="server" Text="Creëer subsite" value="Submit"/>

As soon as i click the button, the page refreshes and the input stays in the textboxes, but nothing happens. The site doesn't get created. This code is part of a SharePoint hosted add-in and i placed it in the page default.aspx. I tried putting the javascript in the App.js but that didn't work either.

I'd appreciate if anyone could tell me what's going wrong here, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.