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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:57:15+00:00 2026-05-31T09:57:15+00:00

I am having problems with the following code: I have n numbers of select

  • 0

I am having problems with the following code:
I have n numbers of select box, whose id are differentiated by the values that the variables ModName and level take:

container.innerHTML = '<form id="listToolForm_'+ModName+level+'"><select id="listToolSelect_'+ModName+level+'" onChange="selValue(this.selectedIndex,'+ModName'+, level)"><option value="0">---</option></select></form>';

The select box is then populated by values taken from a database (this part is not really relevant here). With each form, there is a hidden input with id= idArg'+ModName+'_lev'+level, that will store the index selected by the user, using onChange and the function selValue(x):
Here is the function selValue(index, ModName, level):

function selValue(index, ModName, level){
    document.getElementById("idArg"+ModName+"_lev"+level).value = index;
}

I tried the script setting var ModName = "SL", and var level = 0. I get an error: ‘SL is not defined’. Another test that worked is by replacing the function that fires up onChange:

onChange="selValue(this.selectedIndex)"

and

function selValue(index){
    var level = 0;
    var ModName = "SL";
    document.getElementById("idArg"+ModName+"_lev"+level).value = index;
}

So if the function fired up onChange has one argument, the code works, but does not when using several arguments. I suspect it’s because of the line:

onChange = "selValue(this.selectedIndex,'+ModName'+, level)"

I tried:

onChange="'+window["selValue"](this.selectedIndex, ModName, level)+'"

without success.

  • 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-31T09:57:16+00:00Added an answer on May 31, 2026 at 9:57 am

    The following (I assumed '+ModName'+ was a typo in the question and not in the actual code):
    onChange="selValue(this.selectedIndex, ' + ModName + ', level)"
    causes JavaScript to substitute ModName with its value, which results in the actual HTML being:
    onChange="selValue(this.selectedIndex, SL, level)"
    When handling the onChange event, the JavaScript engine “thinks” SL is a variable (hence the error), but you actually want it to be a string (if I understood well).

    To turn SL into a string, you should surround it with single quotes. To do that, you will need the \' escape sequence, since you’re already using nested quotes. Simply replace:
    onChange="selValue(this.selectedIndex, ' + ModName + ', level)"
    with:
    onChange="selValue(this.selectedIndex, \'' + ModName + '\', level)"

    Also, didn’t you mean:
    onChange="selValue(this.selectedIndex, \'' + ModName + '\', ' + level + ')"
    ?

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

Sidebar

Related Questions

I have the following code, and am having some problems with it. Any help
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I am having the following problem. I have the numbers 1/2/3/4/5/6 and I want
Dear competent people. I'm having a problem with the following code, specifically that the
I'm having problems finding out what's wrong with the code below. I have consulted
I'm having a problem getting a change event to register with the following code:
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
I'm having a problem with image scaling. When I use the following code to
I'm having problems compiling the following program. I'm using gcc -framework Foundation inherit8.1m and
I am having problems with the following query in Castle ActiveRecord 2.12: var q

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.