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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:45:41+00:00 2026-05-30T10:45:41+00:00

I have a problem in passing an array to a function in JavaScript. I

  • 0

I have a problem in passing an array to a function in JavaScript.

I have a Room with walls that has to be saved, but there are too many elements so i split them in parts. When u click on “save” this is the first function that is called:

function getCompleteParamlist(id)
{
var paramlist = $("#edit_form_"+id).serialize();
var params = paramlist.split("&");

var id                      = params[0];
var name                    = params[1];
var x_max                   = params[2];
var y_max                   = params[3];
var tools                   = params[4];
var style_toolbrush         = params[5];
var roompiece_brushchooser  = params[6];
params.splice(0,7);
var y = y_max.replace(/\D/g, '');
var length = params.length;

var fixed_params = id+"&"+name+"&"+x_max+"&"+y_max+"&"+tools+"&"+style_toolbrush+"&"+roompiece_brushchooser+"&y_val=";

prepareSaveRoom(fixed_params,params,y,length,1);
}

It gets all the values that are going to be saved, splits them into an array and builds an a string of params used every time. Removed the already used parameters and calls the next function:

function prepareSaveRoom(fixed_params,params,loops,length,count)
{
    var temp_paramlist  = fixed_params+count;

for(var i=1; i<=length/loops; i++)
{
    temp_paramlist += "&"+params[0];
    params.splice(0,1);
}

if (count == loops)
{
    temp_paramlist += "&last=true";
    saveRoom(temp_paramlist,1,fixed_params,params,loops,length,count);
}
else
{
    temp_paramlist += "&last=false";
    count++;
    saveRoom(temp_paramlist,0,fixed_params,params,loops,length,count);
}
}

This works on the first run and the new temporary parameterlist is build and the saveRoom function is called. This builds a partial parameterlist that is going to be saved. removed the objects from the array and calls the save funvtion

function saveRoom(temp_paramlist,lastloop,fixed_params,params,loops,length,count)
{
alert(temp_paramlist);
$.ajax({
    type: "POST",
    dataType: "html",
    url: "SaveRoom?"+temp_paramlist,
    contentType: "application/x-www-form-urlencoded;charset=UTF-8",
    cache: false,
    success: function(data){
        if(lastloop == 1){
            location.href=data;
        }
        else{
            window.setTimeout("prepareSaveRoom('"+fixed_params+"','"+params+"','"+loops+"','"+length+"','"+count+"')",2000);
        }
    },
    error: function(data){
        showErrorDialogHandleSecondDiv(data.responseText,"#edit_room");
    }
}); 
}

This method calls a Java Controller which saves the values and then it calls the prepareSaveRoom function again, until all parameters are handled. But when saveRoom() calls prepareSaveRoom and it gets to the point:

for(var i=1; i<=length/loops; i++)
{
    temp_paramlist += "&"+params[0];
    params.splice(0,1);
}

I get the error that the Object has no method ‘splice’.
I can’t find the bug and so I’m trying to find some help here.
i don’t know why i can’t call splice on the parameter array that is passed from function to function.

Thanks for reading and possible help 🙂

  • 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-05-30T10:45:42+00:00Added an answer on May 30, 2026 at 10:45 am

    You’re converting everything into a string. In fact, you’ve explicitly enclosed params with quotes as if you wanted it to be a string:

    window.setTimeout("prepareSaveRoom('"+fixed_params+"','"+params+"','"+loops+"','"+length+"','"+count+"')",2000);
    

    Strings do not have .splice. You want to pass the array params, not a string representation of it.

    Another reason not to pass a string to setTimeout. You should pass a function at all times:

    window.setTimeout(function() {
        prepareSaveRoom(fixed_params, params, loops, length, count);
    }, 2000);
    

    That way, you indeed pass an array (so no string conversion).

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

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have a problem with passing of an array from Fortran to a c
I have this problem with Cocoa, I am calling a function and passing an
I have this function that takes a pointer of an array (in order to
I'm experimenting with WCF Services, and have come across a problem with passing Interfaces.
My problem is similar to Django Passing Custom Form Parameters to Formset Ive have
I am having a problem with views. I have a view and am passing
I'm attempting to simplify my code with a function that generates an array of
I have a javascript function in which I want to open a new window
I have a problem calling an anonymous function with parameters passed as variables. If

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.