如果下拉列表具有某个值,则如何获取下拉列表的选定值 [英] how to take selected value of a dropdownlist when already that dropdown has some value

查看:73
本文介绍了如果下拉列表具有某个值,则如何获取下拉列表的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,当我点击编辑页面时,根据数据库中存在的值选择dropdwonlist,如果我想在dropdwonlist中选择其他选项并获取它的值如何做,我不想使用change()函数



这是我的代码,当页面初始化

$(。editVehicle)。click(function() {

$(。hiddenVehicleId)。val($(this).attr(VehicleID));



$( #editvehicleNo)。val($(this).attr(VehicleNo));



$(#VehicleId option [value ='+ $ (this).attr(VehicleType)+'])。attr(selected,selected);

$(#DriverId option [value ='+ $(这个).attr(DriverName)+'])。attr(selected,selected);

$(#editGpsName)。val($(this)。 attr(GPSName));



$(#editvehicleNo)。attr(禁用,禁用);



});



和whe ni更改值并单击保存按钮



i have a dropdownlist where when i click edit page the dropdwonlist is selected based on the value present in database, if i want to select someother option in tht dropdwonlist and take a value of it how to do it,i dont want to use change() function

here is my code when the page inititlizes
$(".editVehicle").click(function () {
$(".hiddenVehicleId").val($(this).attr("VehicleID"));

$("#editvehicleNo").val($(this).attr("VehicleNo"));

$("#VehicleId option[value='" + $(this).attr("VehicleType") + "']").attr("selected","selected");
$("#DriverId option[value='" + $(this).attr("DriverName") + "']").attr("selected", "selected");
$("#editGpsName").val($(this).attr("GPSName"));

$("#editvehicleNo").attr("disabled", "disabled");

});

and when i change the values and click save button

$("#btnEditSave").click(function () {


      var VehicleNo = $("#editvehicleNo").val();

      var VehicleName = $("#VehicleId option:selected").val();

      alert(VehicleName);
      var DriverName = $("#DriverId ").val();

      var GpsName = $("#editGpsName").val();

      var UrlEditVehicle = getFulURL("Home/UpdateVehicleList");
      $.ajax({
          url: UrlEditVehicle,
          type: 'GET',
          datatype: "json",
          traditional: true,
          data: {
              VehNo: VehicleNo,
              VehName: VehicleName,
              DriverName: DriverName,
              Gps: GpsName
          },
          sucess: function (data) {

              $("#lblStatus").css("color", "Green").text("Vehicles Edited Successsfully").fadeOut(9000);




              $("#VehicleList").html("");
              $("#VehicleList").html(data);
          },
          error: function (data) {
              $("#lblStatus").css("color", "Red").text("Unsuccesful in Editing").fadeOut(9000);
          }
      });

  });









在这里我得到了dropdwon值作为页面加载时的值



请帮助解决方案???





here i am getting the dropdwon value as the value when the pageload happens

pls help with the solution???

推荐答案

(。editVehicle)。click(function(){
(".editVehicle").click(function () {


(。hiddenVehicleId)。val(
(".hiddenVehicleId").val(


(this).attr(VehicleID));


(this).attr("VehicleID"));


这篇关于如果下拉列表具有某个值,则如何获取下拉列表的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆