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 7770931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:31:35+00:00 2026-06-01T16:31:35+00:00

I have create a function so that it would load the function whenever call

  • 0

I have create a function so that it would load the function whenever call that function through the button. But it works only when I refresh the page but not working when I hit the Swap button.

Here is the link http://www.onlinedemowebsite.com/design/swatch/drag-and-drop/try3.html

Can anyone help me to solve the problem.

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-01T16:31:36+00:00Added an answer on June 1, 2026 at 4:31 pm

    You have onclick=”shuffle()” on the swap button and that function is not defined in the global scope which the event will be fired within. Either move the function to the window scope, or create the DOM-node and attach a real event to it instead of using document.writeln

    Also, the shuffle function use document.writeln, an example would be to revise it and do something like this instead:

    function shuffle(){
        //organize and sort your letters here
        var letters = ....
        //query for all elements with class = 'letters' use a library if you want full browser support.
        var letter_nodes = document.querySelectorAll("div.letters"); 
    
        for ( var i = 0, n = letter_nodes.length; i<n; ++i ) {
            letter_nodes[i].innerHTML = letters[i]; // letters and letter_nodes array should have the same length.
        }
    }
    

    Edited:

    change your shuffle function to look like this:

    var letters=['A','B','E','F','O','M','I','T']; //to access letters.length in the other function
    function shuffle(){
        letters.sort(function(){return 0.5 - Math.random();});
    
        var letter_nodes = document.getElementById('lettersContainer');
        letter_nodes = letter_nodes.getElementsByTagName('div');        
    
        for ( var i = 0, n = letter_nodes.length; i<n; ++i ) {
            letter_nodes[i].innerHTML = letters[i];
        }
    
        return false;
    }
    

    then change the part where you create the container (in print_2d_string_array)

        document.writeln ("<a href='#' onclick='return shuffle()' class='swap'>Swap</a>");
        document.writeln ("<div id='lettersContainer'>");
    
        for ( var i = 0; i < letters.length; ++i ) {
        document.writeln ("<div class='letters'></div>");
        }
    
        shuffle();
        document.writeln ("</div>"); /* lettersContainer end */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three classes that all have a static function called 'create'. I would
I have this class that have a function to load other classes and create
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1
Does anyone have a working class or function to create the hashed email that
When you have a function with a string parameter, does that create another instance
I have created a function in PHP that calls a webservice and parses through
I am wanting to create a page that can load a property file into
I have a page (parent) that when a button (with .click funciton) is clicked
i have a paging grid and some function that load a new store to
I would like to create a jQuery function that I can attach to form

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.