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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:18:52+00:00 2026-05-23T07:18:52+00:00

I want to pass a Javascript variable as a argument of a function called

  • 0

I want to pass a Javascript variable as a argument of a function called on onclick event of a checkbox, and the checkbox is created in innerHTML.
The code snippet is:

function populateValue(Result) {
    var valueSet = new Array();
    valueSet = Result.split("##");
    for (i = 1; i < valueSet.length - 3; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");
        tr.setAttribute("align", "left");
        tr.className = "table_ce11";
        td.setAttribute("align", "center");
        var code = String(valueSet[i - 1]);
        td.innerHTML = "<input type='checkbox' name='pCheckBox' value='111' id ='" + code + "' onClick=\"javascript:decide('" + code + "')\">";

        tr.appendChild(td);
    }
}

function decide(code) {
    alert("here");
    alert(document.getElementById(code).value);
    if (document.getElementById(code).checked) alert("chked");
    else alert("unchked");
}

while running this, neither am able to set the id nor to pass the argument of the function decide(). I get the error:

"undetermined string constraint".

But if I hardcode the values the function runs fine.
Any suggestions on this?

  • 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-23T07:18:53+00:00Added an answer on May 23, 2026 at 7:18 am

    Just for starters

    Split creates an array.

    var valueSet = Result.split("##");

    You need to test if there ARE at least 4 items in the array

    if (valueSet.length <= 3) return 
    for (var i = 1; i < valueSet.length - 3; i++) {
    

    no need to create a string when you string concatenate a string anyway

    var code = valueSet[i - 1];

    No need to use javascript: prefix and no need to pass the code when it is the same as the ID:

    td.innerHTML = '<input type="checkbox" name="pCheckBox" value="111" id ="' + code + '" onClick="decide(this.id)">';

    Also default align is left and you align center on the cell so get rid of

    // tr.setAttribute("align", "left");

    can you post more of the code and tell where things are going wrong exactly?

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

Sidebar

Related Questions

I want to pass a Java string variable to Javascript function which I am
I want to pass in the tType of a class to a function, and
I want to pass a variable to a UIButton action, for example NSString *string=@one;
I am writing PHP code where I want to pass the session id myself
I have a variable inside my php file, which I want to pass to
What's the best way to pass in the value held in a javascript variable
I have the following line of code: <a href=javascript:; onClick=tweeet('myid')>My Tweets!</a> Now while this
I want to pass an integer value to a form in .Net so that
I want to pass an int list (List) as a declarative property to a
I want to pass an enum value as command parameter in WPF, using something

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.