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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:32+00:00 2026-06-17T15:31:32+00:00

I have an Editor Template which contains a table row with (among other stuff)

  • 0

I have an Editor Template which contains a table row with (among other stuff) a dropdown/combobox to select a currency. This edit template is shown many times on the same View and it’s possible for a user to add these rows as many times as he wants.

I want changes on a row’s dropdown to reflect in an EditorFor (the currency’s rate) on the same row, so I’ve added a onchange html parameter:

<td>
    @*@Html.LabelFor(model => model.Currency)*@
    @Html.DropDownListFor(model => model.Currency, new SelectList(Model.CurrencyList, "Code", "Code"), new { onchange = "updateCurrency(this)" })
    @Html.ValidationMessageFor(model => model.Currency)
</td>

My javascript function makes an ajax call to retrieve the rate for the selected currency:

function updateCurrency(elem) {
        alert("Currency changed!")
        $.ajax({
            type: "GET",
            url: "Currency?code=" + elem.value,
            success: function (msg) {
                // The Rate field's Id:
                var RateId = "@Html.ClientIdFor(model=>model.Rate)" //  // Halp, problem is here!
                document.getElementById(RateId).value = msg;

            }
        });
    }

My problem is that

var RateId = "@Html.ClientIdFor(model=>model.Rate)"

has that Html helper which is server-side code. So when i view the page’s source code, the javascript code is replicated (once for each row) and all the var RateId = “@Html.ClientIdFor(model=>model.Rate)” are pointing to the most recently added column’s EditorFor.

Probably my way of attempting to solve the problem is wrong, but how can I get my javascript code to update the desired field (i.e. the field in the same row as the changed dropdown list).

I believe that one of the problems is that I have the javasript on the Editor Template, but how could I access stuff like document.getElementById(RateId).value = msg; if I did it like that?

Thanks in advance 🙂

  • 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-17T15:31:33+00:00Added an answer on June 17, 2026 at 3:31 pm

    Figured it out. Hoping it helps somebody:

    In my view:

    @Html.DropDownListFor(model => model.Currency, new SelectList(Model.CurrencyList, "Code", "Code"), new { @onchange = "updateCurrency(this, " + @Html.IdFor(m => m.Rate) + ", " + @Html.IdFor(m => m.Amount) + ", " + @Html.IdFor(m => m.Total) + ")" })
    

    In a separate JavaScript file:

    function updateCurrency(elem, RateId, AmountId, TotalId) {
    
       var cell = elem.parentNode // to get the <td> where the dropdown was
    
       var index = rowindex(cell) // get the row number
    
       // Request the currency's rate:
       $.ajax({
    
          blah blah blah .........
          (RateId[index - 1]).value = 'retreived value'; // Set the rate field value.
    
       });
    
    }
    

    Seems to be working so far.

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

Sidebar

Related Questions

I have an editor template with a dropdown: @Html.DropDownListFor(m => m.AdmissionState, new List<SelectListItem>() {
I have created an editor template for representing selecting from a dynamic dropdown list
I have an editor which is in my window that contains a wrapping iframe
I have an editor template (Views/Shared/EditorTemplates/HORDER.ascx) which inherits System.Web.Mvc.ViewUserControl<CCOK2.Models.HORDER> My viewmodel has a one-to-many
We have an editor template that contains approx 40 lines of jquery. I tried
I have a complex view model which contains a collection of other objects which
I have an Editor Template for my Date fields which sets the current date
I have an image uploader editor template, which is currently strongly typed to the
In my view I call Html.EditFor() which triggers a custom editor-template for this datatype.
I have the following in my Razor view for an editor template in my

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.