Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello my database is eqdam and three column id eqdamname eqdamprice
namespace Pooya.Models.DomainModel
{
    using System;
    using System.Collections.Generic;
    
    public partial class Eqdam
    {
        public int Id { get; set; }
        public string EqdamName { get; set; }
        public decimal EqdamPrice { get; set; }
    }
}


function LoadEqdam(element) {
    if (Eqdams.length == 0) {
        $.ajax({
            type: "GET",
            url: '/User/getEqdams',
            success: function (data) {
                Eqdams = data;
                renderEqdam(element);
            }
        })
    }
    else {
        renderEqdam(element);
    }
}

function renderEqdam(element) {
    var $ele = $(element);
    $ele.empty();
    $ele.append($('<option />').val('0').text('Select'));
    $.each(Eqdams, function (i, val) {
        $ele.append($('<option/>').val(val.EqdamName).text(val.EqdamName));
    })
}


public JsonResult getEqdams()
     {
         List<Eqdam> Eqdams = new List<Eqdam>();
         using (PooyaEntities dc = new PooyaEntities())
         {
             Eqdams = dc.Eqdams.OrderBy(a => a.EqdamName).ToList();
         }
         return new JsonResult { Data = Eqdams, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
     }

this code produce e dropdown list for eqdam name .

What I have tried:

I want to change the value dropdown change price in the labels
Posted
Updated 8-Apr-18 5:13am
v3

1 solution

Try with data attribute, it will help u.

function renderEqdam(element) {
    var $ele = $(element);
    $ele.empty();
    $ele.append($('<option />').val('0').text('Select'));
    $.each(Eqdams, function (i, val) {
        $ele.append($('<option/>').val(val.EqdamName).text(val.EqdamName).attr('data-EqdamPrice', val.EqdamPrice ).attr('data-id', val.id));
    })
}



$('#foo').on("change",function(){
    var dataid = $("#foo option:selected").attr('data-EqdamPrice');
    alert(dataid)
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900