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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:22:44+00:00 2026-06-12T09:22:44+00:00

I have a drop down list which contains a list of visits which are

  • 0

I have a drop down list which contains a list of visits which are displayed like so:
5/3/2012 At School Below this dropdown list are A Date field and a visit type dropdown list. I would like to populate these fields based on the first dropdown list. so for this example the date field will be filled with 5/3/2012 and the visit type will be: At School

I am using javascript to use it but i am having an error window saying [object Object].

Here is my code:

JavaScript:

<script type="text/javascript">

var durationRowVisibilityCheck = function () {
    var disableDuration = $.trim($("select#UnableToVisitReasonId option:selected").text()).length != 0;
    var $durationRow = $("#visitDuration");
    if (disableDuration) $durationRow.hide(); else $durationRow.show();
};

$(function () {
    durationRowVisibilityCheck();
    $("select#UnableToVisitReasonId").change(function () {
        durationRowVisibilityCheck();
    });
    $("#VisitEntryId").change(function(e) {
        var visitEntryId = $("#VisitEntryId.option:selected").val();
        if (visitEntryId != '<%=Guid.Empty %>')
            GetVisitDetails(visitEntryId);
    });
});
function GetVisitDetails(visitEntryId) 
{
    $.ajax({
            url: '<%=Url.Action("GetVisitDetails", "VisitActivity") %>' + '?visitEntryId=' + visitEntryId,
            contenttype: "application/json; charset=utf-8",
            success: function(json) {
                populate(json);
            },
            error: function (xhr, status, error) {
                alert(xhr);
            },
            type: "POST",
            datatype: "json"
        });
    }
function populate(data) {
    $("#ActivityDate").val(data.VisitDate);
    $("#VisitTypeId").val(data.VisitTypeId);
}

Get Details method:

public JsonResult GetVisitDetails(Guid visitEntryId)
    {
        var model = new VisitDetailModel();
        VisitEntry visitEntry = _visitEntryService.Get(visitEntryId);
        if(visitEntry == null)
        {
            model.Message = string.Format(Message.NotFoundMessage, Resources.Entities.Visit.EntityName);
            return Json(model);
        }
        model.VisitEntryId = visitEntryId;
        model.VisitTypeId = visitEntry.VisitTypeId;
        if (visitEntry.VisitType != null)
            model.VisitType = visitEntry.VisitType.Description;
        model.VisitDate = visitEntry.VisitDate.ToShortDateString();
        return Json(model);
    }

    #region Nested Type:VisitDetailModel

    public class VisitDetailModel
    {
        public Guid VisitEntryId { get; set; }
        public short VisitTypeId { get; set; }
        public string VisitType { get; set; }
        public string VisitDate { get; set; }
        public string Message { get; set; }
    }
  • 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-12T09:22:45+00:00Added an answer on June 12, 2026 at 9:22 am

    Try replacing

    datatype: "json"
    

    with:

    dataType: "json"
    

    or completely get rid of it because jQuery is smart enough to use the response Content-Type header from the server and automatically parse the response for you.

    Also remove:

    contenttype: "application/json; charset=utf-8",
    

    You are not sending any JSON to the server. You are sending a normal request.

    So, here’s how to adapt your $.ajax call:

    $.ajax({
        url: '<%= Url.Action("GetVisitDetails", "VisitActivity") %>',
        type: 'GET',
        cache: false,
        data: { visitEntryId: visitEntryId },
        success: function(json) {
            populate(json);
        },
        error: function (xhr, status, error) {
            alert(xhr);
        }
    });
    

    Because I have specified GET verb for the AJAX request (which is the correct verb to be used for retrieving data from the server), you need to adapt your GetVisitDetails controller action so that it sends JSON over GET which is not allowed by default:

    return Json(model, JsonRequestBehavior.AllowGet);
    

    Also the following selector seems wrong to me:

    var visitEntryId = $("#VisitEntryId.option:selected").val();
    

    Try directly retrieving the selcted value of the dropdown in the .change() event handler:

    $('#VisitEntryId').change(function(e) {
        var visitEntryId = $(this).val();
        if (visitEntryId != '<%=Guid.Empty %>')
            GetVisitDetails(visitEntryId);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one drop down list in my page, which contains two options. What
I have a page, it has a drop down list, which contains the names
I have a drop down list (ddlFilterBuildings) which contains a list of buildings to
I have a drop-down list which is generated based on the following sql query:
I have a drop down list which is dynamically generated using ajax on page
I have code which has a drop down list. And when a certain option
I have a dropdown list (FK) which I would like to set and display
Basically I have a drop down list which is populated with text and values
i have a drop down list contains the name of reports and each report
I currently have a dropdown box which contains a list of all of the

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.