I have an MVC app that pops up a window when the user clicks on a button from the parent form. In the pop up window the user selects an element from a list . I seem to be getting the element value correctly , but when i try to update the text box in the
parent form, it doesnt update,
I am trying to use Jquery to achieve this . Is there an example on this.
check in developer tool what is getting generated. Are you getting a popup with iframe or it simply a div kind. If it not iframe or a new popup window you can directly access the control with normal jquery selector.
Thanks & Regards
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Marked as answer by robby32 on Nov 25, 2012 09:09 PM
robby32
Member
120 Points
498 Posts
How can i update a parent form from a child popup ?
Nov 19, 2012 09:44 AM|LINK
Hi,
I have an MVC app that pops up a window when the user clicks on a button from the parent form. In the pop up window the user selects an element from a list . I seem to be getting the element value correctly , but when i try to update the text box in the parent form, it doesnt update,
I am trying to use Jquery to achieve this . Is there an example on this.
thanks
Robby
DarrellNorto...
All-Star
86555 Points
9624 Posts
Moderator
MVP
Re: How can i update a parent form from a child popup ?
Nov 19, 2012 09:56 AM|LINK
Using jQuery, something like this would work. Just replace the #IDs with the names of your various forms and select list elements.
$("#popupWindowLink").click(function() { value = $("#popupForm .selectListID".val(); window.opener.$("#parentForm .someFormInputItem").val(value); window.opener.$("#parentForm").submit(); window.close(); });Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
asteranup
All-Star
30184 Points
4906 Posts
Re: How can i update a parent form from a child popup ?
Nov 19, 2012 10:07 AM|LINK
Hi,
You can also try-
parent.$("input[id*=textboxid]").val("value from popup");
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
robby32
Member
120 Points
498 Posts
Re: How can i update a parent form from a child popup ?
Nov 19, 2012 10:18 AM|LINK
Hi,
I have tried it with the following, but how can i get the parent form name . I am using trying to use Razor with Jquery .
thanks
@using Kendo.Mvc.Extensions; @using Kendo.Mvc.UI; <html> <body> <table> <tr> <td class="editor-label"> @Html.LabelFor(model => model.CurrencyCode) </td> <td class="editor-field"> @*@(Html.Kendo().ComboBoxFor(model => model.CurrencyCode) .DataSource(source => { source.Read(read => { read.Action("GetCurrencies", "Currency"); }) .ServerFiltering(true); }) .DataTextField("Code") .DataValueField("Code") .Text("AUD") .Filter(FilterType.StartsWith).MinLength(1).Enable(true).IgnoreCase(true) .Name("CurrencyAutoComplete").Suggest(false))*@ <table> <tr> <td > <input name="CurrencyCode" id="CurrencyCode" style="width:auto" data-bind="value:CurrencyCode" data-value-field="Code" data-text-field="Code" data-source="autoCompleteDownDataSource" data-role="autocomplete"/> <span id="openButton" class="k-select" style="border:1px solid black"><span class="k-icon k-i-arrow-s"></span></span> <div id="lookupWindow"> @(Html.Kendo().Grid<ProfAdv.CreditCardImport.Models.Currency>() .Name("gridCurrency") .DataSource(dataSource => dataSource .Ajax() .Model(model => model.Id(m => m.Code)) .Read(up => up.Action("GetCurrenciesLookup", "Currency")) .PageSize(8) ) .Columns(columns => { columns.Bound(c => c.Code); columns.Bound(c => c.Name); }) .Pageable() .Sortable() .Filterable() .Selectable(s => s.Mode(Kendo.Mvc.UI.GridSelectionMode.Single)) .Resizable(resize => resize.Columns(true)) .Reorderable(reorder => reorder.Columns(true)) ) </div> </td> </tr> </table> @Html.ValidationMessageFor(model => model.CurrencyCode) </td> </tr> </table> <script> var autoCompleteDownDataSource = new kendo.data.DataSource({ transport: { read: "Currency/GetCurrencies", }, serverFiltering: true, serverPaging: true, pageSize: 20, ignoreCase: true, minLength: 1, suggest: false, scrollable: { virtual: true }, schema: { model: { fields: { Code: { type: "string" }, Name: { type: "string" } } } } }); $(document).ready(function () { $("#lookupWindow").kendoWindow({ draggable: false, height: "355px", modal: true, resizable: false, title: "Lookup Currencies", width: "500px", visible: false }); $("#openButton").click(function () { var win = $("#lookupWindow").data("kendoWindow"); win.center(); win.open(); }); $("#gridCurrency").delegate("tbody>tr", "dblclick", function () { var data = $("#gridCurrency").data("kendoGrid").dataItem($(this)); var code = data.Code; if ((code != 'undefined') || (code != null)) { debugger; window.parent.$("#parentform.CurrencyCode").val(code); window.parent.$("#parentform").submit(); } var win = $("#lookupWindow").data("kendoWindow"); win.close(); }); }); </script> </body> </html>asteranup
All-Star
30184 Points
4906 Posts
Re: How can i update a parent form from a child popup ?
Nov 20, 2012 01:53 AM|LINK
Hi,
check in developer tool what is getting generated. Are you getting a popup with iframe or it simply a div kind. If it not iframe or a new popup window you can directly access the control with normal jquery selector.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
robby32
Member
120 Points
498 Posts
Re: How can i update a parent form from a child popup ?
Nov 23, 2012 01:42 AM|LINK
Hi ,
I was wanting to update the model , hence the currencycode will be updated.
So I was trying to get a reference to the model object , in my case the parent form and hence I may be able to access the model , is that correct ?
thanks
Robby
robby32
Member
120 Points
498 Posts
Re: How can i update a parent form from a child popup ?
Nov 25, 2012 09:09 PM|LINK
Resolved now thanks.