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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:34:50+00:00 2026-05-28T07:34:50+00:00

I have an xsl page which uses <xsl:variable name=pos select=Position()/> in the onchange events

  • 0

I have an xsl page which uses

 <xsl:variable name="pos" select="Position()"/> 

in the onchange events

onchange="updateDropdown({$pos});someElement_{$pos}.value = {$pos}";

When evaluated on page p=load this will be read as

onchange="updateDropdown(1);someElement_1.value = 1";
onchange="updateDropdown(2);someElement_2.value = 2";
onchange="updateDropdown(3);someElement_3.value = 3";

When I add a row to the bottom of this using a button which copies the entire first row to the bottom it had to go through and update these numbers because it is not handled

I do

lastRowEl = rowEls[rowEls.length-1];

then

lastRowEl.id = "element_" + rowEls.length
lastRowEl.value = "";

finally,

lastRowEl.onchange = lastRowEl.onchange.replace(/\d/g, rowEls.length)

id gets changed to element_4
value gets modified to blank

but onchange.replace does not work and so onchange remains as

onchange="updateDropdown(1);someElement_1.value = 1";

instaead of

onchange="updateDropdown(4);someElement_4.value = 4";

How can I replace all numbers in an onchange function and reset the onchange function with the numbers modified for the element in the last row?

Thanks

  • 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-28T07:34:51+00:00Added an answer on May 28, 2026 at 7:34 am

    This seems a bit weird and I wonder why it works at all, since the value returned by your lastRowEl.onchange is most likely a Function and not a String. Some automatic toString() call seems to happen on your platform (doesn’t work when I test this in Safari). However, the result will most likely be a multiline string and you will probably need to use multiline RegExps, e.g. /\d/mg.

    Even if this works it is pretty ugly. What about defining a function which does all the calls you put into your handler?

    function onchangeHandler(index) {
        updateDropdown(index);
        window["someElement_" + index].value = index;
    }
    

    You would then assign these handler functions in HTML

    < ... onchange="onchangeHandler(1);" .... />
    

    and update them in Javascript

    (function() {
        var index = rowEls.length;
        lastRowEl.onchange = function() {onchangeHandler(index);};
    })();
    

    Note that the closure around the assignment is may not be necessary depending on your surrounding code. You will most likely need the explicit index variable definition, though.

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

Sidebar

Related Questions

I have a xsl:variable ($features-list) specified in my XSL which contains a tree fragment
I have an incoming message hitting my XSL page. On this XSL page I
I have the following XML <?xml version=1.0 encoding=ISO-8859-1?> <?xml-stylesheet type=text/xsl href=example3.xsl?> <pics> <page no=1>
I have nested xsl:for loops: <xsl:for-each select=/Root/A> <xsl:for-each select=/Root/B> <!-- Code --> </xsl:for> </xsl:for>
I have an xsl:fo style sheet that refers to a URL which is an
I have an XSL style sheet for which I need to add some custom
I have some code that uses xsl and xml. The Xml control is on
I have 3 XSL files which have paths in them to something like C:\templates\Test\file.pdf
Currently I have some xml documents which are converted via xsl into html. The
I have a JSP which attaches a XSL to an XML document pulled from

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.