Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:41:49+00:00 2026-06-08T13:41:49+00:00

For some reason the spinner object is working only if it is defined inside

  • 0

For some reason the spinner object is working only if it is defined inside the startSpin() function.

This is the non-working code:

<script type="text/javascript" src="resources/js/spin.js"></script>
    <script type="text/javascript">
        var opts = {
            lines: 18, // The number of lines to draw 
            length: 40, // The length of each line
            top: 'auto', // Top position relative to parent in px
            left: 'auto' // Left position relative to parent in px
        };

         // -- not support ? 
        var target = document.getElementById('spin');
        var spinner = new Spinner(opts).spin(target);
        // -- ???
        function startSpin()
        {
            spinner.start();   
        }
        function stopSpin()
        {
            spinner.stop();  
        }

        function showStatus() {
            startSpin();
            statusDialog.show();
        }

        function hideStatus() {
            stopSpin();
            statusDialog.hide();
        }
    </script>
    <h:form id="testfm">
        <p:commandButton id="start" type="submit" 
                         ajax="false" 
                         value="test" 
                         actionListener="#{bean.test}" 
                         onclick="PrimeFaces.monitorDownload(showStatus, hideStatus)"/>
        <p:dialog modal="true" 
                  widgetVar="statusDialog" 
                  showHeader="false"
                  draggable="false" 
                  closable="false" 
                  resizable="false">
            <div id="spin" class="spinner"/>
        </p:dialog>
    </h:form>

the spinner is working only when it is defined inside the spinStart function

I try to play with the script position but still get the same message
any idea why?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:41:51+00:00Added an answer on June 8, 2026 at 1:41 pm

    You you run document.getElementById('spin') outside of that function, the element with id=spin has not been created yet, so you are giving a null value to the spinner. If you create it inside startSpin, it is in response to a click event from the user, so the DOM has likely been built at that point and the element exists. Here is a workaround:

        var spinner;  //Lave the variable out here so both functions can see it
    
        function startSpin() {
            var target = document.getElementById('spin');
            spinner = new Spinner(opts).spin(target);  //Actually create it here, when the element exists
            spinner.start();   
        }
        function stopSpin() {
            spinner.stop();  
        }
    

    You could also leave the code as it is and put it at the end of your document, just before the </body> tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
For some reason this isn't working for me. It gives me the vector iterator
For some reason this function is doing something weird just in Firefox function fadeOUT_sect(id)
For some reason there's a variable called d that is defined immediately after I
For some reason, my script isn't writing out the text after I remove the
For some reason my simple jquery bind event isn't working. The funny thing is
for some reason my event data isn't working correctly with jquery fullcalendar when I
For some reason (probably because i don't understand closures) function inResult always returns false
For some reason if I try to display data with the following code, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.