user1093896
user1093896

Reputation:

Get And Append ID in Javascript

Hey I tried this code for my project and it returns some bad results. getting the last Id does not work properly .

function regionDropDownChanged() {
    var selectedRegionId = getRegionDropDown();
    if (selectedRegionId !== null) {
        var val = selectedRegionId[selectedRegionId.length - 1];
        alert(val);
    } else return;

    $.get("/Common/JsonFunction/GetEnterprisesOfRegion", { regionId: val }, function (fields) {
        fillDropDown(fields, getEnterpriseDropDown());
        enableEnterpriseDropDown();
    });
}

Also enableEnterpriseDropDown() Dropdown does not work after selecting IDs.

 function enableEnterpriseDropDown() {
    var enterpriseDropDown = getEnterpriseDropDown();
    $(enterpriseDropDown).prop('disabled', false);
 }

other methods that I use in my project

function getRegionDropDown() {
    var dropDown = $("#RegionId").val();
    return dropDown;
}

function getEnterpriseDropDown() {
    var dropDown = $("#EnterpriseId");
    return dropDown;
}

remember that I use Choosen Plugin.

Upvotes: 0

Views: 78

Answers (1)

Rohan Kumar
Rohan Kumar

Reputation: 40639

Here you are using array of selectedRegionId but it is a value, as you have called getRegionDropDown() which returns a single value.

var selectedRegionId = getRegionDropDown();

So, you may get undefined in alert in these lines

var val = selectedRegionId[selectedRegionId.length - 1];
alert(val);

If you create a Fiddle then it would be better to solve you problem.

Upvotes: 1

Related Questions