Click here to Skip to main content
15,886,638 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to populate second-textboxe based on first-textbox value on tabbing from database using jquery ajax in mvc4 e.g:
first-textbox is tasks now i want to populate second-textbox(projects)which is related to those tasks..i use this JSOn result function
public JsonResult LoadProjectsByTaskId(int  taskId)
        {
            var query = from tasks in context.Tasks
                        join projects in context.Projects on tasks.ProjectId equals                                     
                        projects.ProjectId
                        select new { tasks, projects };

            return Json(query, JsonRequestBehavior.AllowGet);
        }


and ajax code is
function LoadProjectsByTaskId() {

          $("#textarea").autocomplete({
              source: function (request, response) {
                  debugger;
                  $.ajax({
                      url: "/Home/LoadProjectsByTaskId",
                      type: "POST",
                      dataType: "json",
                      data: { term: request.term },
                      success: function (data) {
                          {
                              response($.map(data, function (item) {
                                  return { label: item.Name, value: item.Name };
                              }))
                           }
                      },
                  });
          }

      }


how can i do that?????
Posted
Comments
Arora_Ankit 28-Oct-14 4:06am    
Add onBlur event on the first textbox and use ajax to get projects for the task in that function.

1 solution

As I understand ,you already have the code for fetching the records.Now you just need to call the server side code and display the returned data.

You can do something like

$( "#TextBoxId" ).blur(function() { LoadProjectsByTaskId();});
Then in the below code block you can set the display properties

success: function (data) {
 
Share this answer
 
Comments
Mohsin Azam 28-Oct-14 8:53am    
Ashish!i can populate one textbox at time but i want to populate first textbox and then second textbox is populated by first textbox parameters....how this can be done..?

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