none
Apps for Office - Task Pane App - Word Javascript Accept Textbox Input Variable RRS feed

  • Question

  • Hi friends,

    How can i make my variable be accepted.

     

    I have created a text box to enter the value of the font size but its not working :(

            function ChangeFontSize() {
            
    		
    		Word.run(function (context) {
        
        // Create a range proxy object for the current selection.
    	
        var selection = context.document.getSelection();
    	//var oSize = document.getElementById("TextBox1").value;
        
        // Queue a commmand to change the current selection's font size.
       // selection.font.size = 20;
    	
    		selection.font.size = TextBox1.value;
    	
    	
        
        // Synchronize the document state by executing the queued-up commands, 
        // and return a promise to indicate task completion.
        return context.sync().then(function () {
            console.log('The font size has changed.');
        });  
    })
    			
                .catch(function (error) {
                    console.log('Error: ' + JSON.stringify(error));
                    if (error instanceof OfficeExtension.Error) {
                        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
                    }
                });
            }

    This is a very basic example

    My Textbox1 is in the main html file

    any help appreciated

    thank you


    Cheers Dan :)


    • Edited by Dan_CS Monday, May 1, 2017 4:18 PM
    Monday, May 1, 2017 4:17 PM

Answers

  • Hello,

    We need to convert string to int and then assign it to font size.

    E.g. Text1 is the id of textbox.

           var oSize= $('#Text1').val();
                selection.font.size = parseInt(oSize);

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Dan_CS Tuesday, May 2, 2017 11:17 AM
    Tuesday, May 2, 2017 4:22 AM
    Moderator

All replies

  • Hello,

    We need to convert string to int and then assign it to font size.

    E.g. Text1 is the id of textbox.

           var oSize= $('#Text1').val();
                selection.font.size = parseInt(oSize);

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Dan_CS Tuesday, May 2, 2017 11:17 AM
    Tuesday, May 2, 2017 4:22 AM
    Moderator
  • Thank you Celeste it worked :)

     

    I am dissapointed i couldnt find this information any where in the documentation on how to set a varibale from a text box input oh well

     

    On to the next task

     

    Thank you


    Cheers Dan :)

    Tuesday, May 2, 2017 11:17 AM