Dear support,
What i want to achieve is this. I have a dropdown list and a text field. When users choose from the dropdown list, the selected item should be used to spool its corresponding record from a table and then output it in a text field.
For instance
Choose branch code: Dropdown menu with branch code like 001,002
Branch Name : Automatically, the branchname for the selected branchcode shows here
The view
<label class="FieldGHN">SBU</label>
@Html.DropDownList("Branchcode", ViewBag.sbulistname as SelectList, "--Select SBU--", new { @id = "DropDown", @class = "SelectCtrlGHN", onchange = "return get_sbu(this)" })
<br />
<label class="FieldGH">Group Head</label>
<input type="text" id="GrpHead" name="GrpHead" value="AutoGenerated" readonly class="PO_GH" /><br />
I am able to populate the dropdown list but i am not able to show the branchname as explained above
The javascript
<script>
function get_sbu()
{
var selected_val = $('#DropDown').find(":selected").attr('value');
//var selected_val = $('#DropDown').val();
$.ajax({ //ajax call
type: "POST", //method == POST
url: "/Home/selectSBU", //url to be called
data: "id=" + selected_val, //data to be send
success: function(data){
$('#GrpHead').val(data); // here we will set a value of text box
}
});
}
</script>
The controller - not sure what to do here
public JsonResult selectSBU(string id)
{
return Json(id, JsonRequestBehavior.AllowGet);
}