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

  • Home
  • SEARCH
  • 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 5845029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:22:36+00:00 2026-05-22T12:22:36+00:00

I am trying to pass a variable in javascript. I create a link in

  • 0

I am trying to pass a variable in javascript. I create a link in the following manner and everything seems to be working.

label.innerHTML = '<a href="#" onclick="show_box(this);"> link</a>';

However when I create the link in the following way where the link would also pass an associated object I get the following error from firebug -> “missing ] after element list”

label.innerHTML = '<a href="#" onclick="show_box(this,'+object+');"> link</a>';

Is this an acceptable way to pass an object to a function. The problem is that I am creating this link within a function. The function creates links like this based upon an object that is passed to it. Therefore I cannot have this “object” as a global scope.

  • 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-22T12:22:36+00:00Added an answer on May 22, 2026 at 12:22 pm

    You are building the script by mashing together strings, as such you can only work with strings and object will be automatically stringified.

    Use DOM instead.

    var link = document.createElement('a');
    link.href = "#"; // Have a more sensible fall back for status bar readers and middle clickers
    link.appendChild(document.createTextNode(' link');
    link.addEventListener('click',function () { show_box(this, object); },false);
    label.appendChild(link);
    

    … but use a library that abstracts away the non-standard event models that some browsers have.

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

Sidebar

Related Questions

We are trying to create a web-service that we plan to pass a variable
I am trying to pass a variable frm php to a javascript function, however
I am trying to pass a php variable inside javascript bt it is not
I'm trying to pass local variables to an inline function in javascript and have
I am trying to pass a variable to a a function that I believe
I am trying to pass one variable to a jQuery function inline (i.e.: using
i'm relatively new to jquery and javascript and am trying to pass a unique
I am trying to pass a variable to a included file. I have done
I am trying to pass a member function within a class to a function
I'm trying to pass in a Base64 string into a C#.Net web application via

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.