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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:55:14+00:00 2026-06-05T13:55:14+00:00

I have a select element which I’m creating through javascript (DOM) var cell_stock_id =

  • 0

I have a select element which I’m creating through javascript (DOM)

var cell_stock_id = row.insertCell(0);
var cell_stock_id_sel = document.createElement('select');

I have kept an onchange javascript function for this-

cell_stock_id_sel.setAttribute("onchange","populateOtherFields");

The function gets called when i change the selected option in select.

Is there a way I can pass an argument to this function “populateOtherFields” ?

I have a select box and a lot of text fields in a table row. I want to populate those rows based on the selection. I’m able to access the data which has to be inserted in those fields, but I don’t know how to enter the data in those textfields for that row. I’m thinking of passing a unique number which will identify with the names of the elements in a row, and the javascript will parse that pattern in the names of the elements of the row.

 document.forms["0"].elements[i].name.indexOf("pattern"). 

So is there a way by which i can pass this “pattern”, which is essentially the iteration (no. of rows, row number) number.

select__1, text__1, text2__1
select__2, text__2, text2__2

The ‘__1’ , and the ‘__2’ need to be passed. And they’re not static patterns. Could be any number.

  • 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-05T13:55:15+00:00Added an answer on June 5, 2026 at 1:55 pm

    Don’t use setAttribute to set up event handlers, use direct assignment or (better) addEventListener / attachEvent and then you can create a function that will call your function with the desired arguments. (You could do that anyway, of course, but using setAttribute you’d either have to do it inline or create yet another global, named function.)

    Direct assignment:

    cell_stock_id_sel.onchange = function() {
        populateOtherFields(arguments, here);
    };
    

    Works on all browsers, but you can only have a single change handler on the element using this method (as with setAttribute).

    addEventListener:

    cell_stock_id_sel.addEventListener('change', function() {
        populateOtherFields(arguments, here);
    }, false);
    

    This is the standard, but it doesn’t exist on older versions of IE.

    attachEvent:

    cell_stock_id_sel.attachEvent('onchange', function() {
        populateOtherFields(arguments, here);
    });
    

    This is IE-only (er, mostly, some browsers throw a bone to IE-only sites). It’s Microsoft’s pre-standard way of doing it. In IE8 and above in standards mode, you can use addEventListener instead.

    Another advantage of all of these methods is that you don’t have to have any global functions, whereas the setAttribute way, if you use a function name, that function has to be global. The global namespace on browsers is already really crowded, I always recommend avoiding adding to the clutter.


    Because of the various vagaries between browsers, I tend to recommend using any decent JavaScript browser library such as jQuery, YUI, Closure, or any of several others. These smooth over differences like the addEventListener / attachEvent thing and also provide a lot of helpful utility functionality.

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

Sidebar

Related Questions

I am creating a web page which will have a Select element with a
I have a simple function which disables/enables select element when checkbox is checked/unchecked. It
I have a <select> element which I need to track using change(). jQuery('.dropdown').change(function(){ yada,
I have an html select element which I would like to style for print
I have a SELECT element in a form which I'm populating using AJAX when
I have a select element from which the users can select a value and
I have a simple html form with select element. To define which option is
I have a SELECT element which adds its value to a hidden INPUT via
I have a SELECT element in which I need to auto-select the appropriate option
I have a list in which i need to select an element (according to

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.