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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:16:29+00:00 2026-06-19T03:16:29+00:00

I am writing a menu system and I need to call a function when

  • 0

I am writing a menu system and I need to call a function when the user clicks on a specific row. I am using new function to pass the div that called the function as well as the row the user clicked on. All well and good until I try to pass a local array to the function. If I do the following:

for (i=0;i<tmpdropnumber;i++){
    var dv=document.getElementById(id+i);
    dv.style.cursor="pointer";  
    dv.onmouseover = new Function('dropover'+"('" + id + "','" + i + "')");
    dv.onmouseout = new Function('dropout'+"('" + id + "','" + i + "')");
    dv.onclick = new Function('dropclick'+"('" + id + "','" + i + "','"+tmparray1+"','"+tmparray2+"')");
}

As you’d expect the arrays are passed as strings. I could rebuild the arrays in the function but that seems inelegant.

if I try the following:

for (i=0;i<tmpdropnumber;i++){
    var dv=document.getElementById(id+i);
    dv.style.cursor="pointer";  
    dv.onmouseover = new Function('dropover'+"('" + id + "','" + i + "')");
    dv.onmouseout = new Function('dropout'+"('" + id + "','" + i + "')");
    dv.onclick = new Function('dropclick'+"('" + id + "','" + i + "',"+tmparray1+","+tmparray2+")");
}

Trying to pass the arrays it crashes. Any ideas on how I can achieve this? I am using jquery in my code so wither a javascript or jquery solution would be fine.

  • 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-19T03:16:30+00:00Added an answer on June 19, 2026 at 3:16 am

    Do not use new Function.

    You are having problems because when the string is being built, the array is being turned into a string.

    basic idea to get around the toString()

    for (i=0;i<tmpdropnumber;i++){
        var dv=document.getElementById(id+i);
        dv.style.cursor="pointer";
        (function(id, i){  
            dv.onmouseover = function(){ dropover(id,i); };
            dv.onmouseout = function(){ dropout(id,i); };
            dv.onclick = function(){ dropclick(id,i, tmparray1, tmparray2); };
        })(id,i);
    }
    

    But in reality there is no need to pass in an object, id.

    You can always use this to get the current row and there is rowIndex on the table. Heck you can have one event handler on the table and use handlers on the table/tbody to capture the bubbling and use target/srcElement.

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

Sidebar

Related Questions

Im writing a simple jquery menu system that shows / hides a DIV on
Im writing an app that has a navigation controller as it's main menu system
I'm writing a script to navigate a text-based menu system, using python's telnetlib to
I Delphi, I need a function which determinates if the system menu (resp. window
I'm writing a Cocoa application that installs itself as an menulet in the menu
I am writing an app that allows a user to access their corporate voice
I'm writing a GUI application that will have a user log in feature. Each
I am writing an application that allows a user to submit a query to
I'm in the process of writing a small/basic CMS system using Symfony 1.4 and
I am writing a menu navigation using basic HTML ul/li lists, basic CSS code,

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.