2011-06-21 17 views
0

我在我的視圖頁面三個按鈕,通過從彈出窗口的父窗口的值表示「Button1的」「Button2的」 & 「將Button3」和我有三個文本框對應對每個按鈕說「TextBox1」,「TextBox2」 & 「TextBox3」。當點擊任意一個按鈕時,我可以打開一個彈出窗口。現在我想將一些值從POP向上視圖傳遞給父視圖,並將該值傳遞給TextBox與正在單擊的按鈕關聯。我怎樣才能做到這一點?如何通過jQuery的MVC中

編輯

<input type="button" value="Buuton1" id="Button1" style="width:100px;font-family:Verdana; font-size:9px; onclick="window.open('<%= Url.Action("Popup", "Home") %>');" /> 
<input type="button" value="Button2" id="Button2" style="width:100px;font-family:Verdana; font-size:9px;" onclick="window.open('<%= Url.Action("Popup", "Home") %>');" /> 
<input type="button" value="Button3" id="Button3" style="width:100px;font-family:Verdana; font-size:9px;" onclick="window.open('<%= Url.Action("Popup", "Home") %>');" /> 
+0

嗨@Saloni,我們需要一些代碼,能夠幫助您。 –

+0

');「/>');「/>');「/> – Saloni

+0

我在視圖頁上有三個texbox:<% = Html.TextBox(「TextBox1」,「」,new {style =「width:40px; font-family:Verdana; font-size:9px;」}}> TextBox2,Textbox3現在,當我點擊任何按鈕我能夠得到一個彈出窗口名稱「彈出」在該彈出窗口中我有一個按鈕和一個文本框當我把一些值的文本框,並點擊按鈕後,我想填充文本框的值父窗口和關閉彈出窗口 – Saloni

回答

2

給一個id文本框(例如textBox1),然後嘗試this..it是一個簡單的JavaScript。
你不需要這個jQuery。

window.opener.document["nameForm"].getElementById("textBox1 ").value = "your some values will go here" 
+0

給出錯誤:Microsoft JScript運行時錯誤:無法獲取屬性'getElementById'的值:對象爲空或未定義 – Saloni

+0

是否已將id添加到文本框,然後將此ID傳遞給''getElementById''函數? – Vivek

+0

正如你所說我做window.opener.document [「nameForm」]。getElementById(「textBox1」)。值=「你的一些價值將會在這裏」我做了同樣的 – Saloni

0

我們可以通過使用jquery或Javascript來做到這一點。這裏我們將討論電子郵件ID更新。

在波紋管示例中,彈出式窗口將從父窗口自動填充電子郵件ID打開。 更新後,電子郵件會自動在父窗口文本框中更新,並彈出窗口將專門關閉。

例子:

1)創建index.html文件爲父窗口

<!DOCTYPE HTML PUBLIC 「-//W3C//DTD HTML 4.0 Transitional//EN」> 
<html> 
<title></title> 
<head></head> 

<body> 
<table> 

<tr> 
<td colspan=」2″>Example for update email id.</td> 
</tr> 
<tr> 
<td>Email Id:</td> 
<td> 
<input type=’text’ name=」emailID」 id=」emailId」 value=」[email protected]」></td> 
</tr> 
<tr> 
<td> 
<input type=」button」 name=」update」 value=」Update」 
onClick=’window.open(「update_popup.html」, 「」, 「width=400, height=300″)’> 
</td> 
</tr> 
</table> 
</body> 
</html> 

2)創建爲彈出窗口,電子郵件ID自動從填文件update_popup.html父窗口進行更新。

<!DOCTYPE HTML PUBLIC 「-//W3C//DTD HTML 4.0 Transitional//EN」> 
<html> 
<title></title> 
<head></head> 
<script src=」http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js」></script> 
<script> 
$(document).ready(function(){ 

//== pre fill parent window email id in popup window for update 

var emailId = window.opener.document.getElementById(「emailId」).value; 
$(「#emailId」).val(emailId); 

//=== update updated email id in to parent window 

$(「#Save」).on(‘click’,function(){ 

var updated_emailId = $(「#emailId」).val(); 
window.opener.document.getElementById(「emailId」).value = updated_emailId; 
window.close(); 
}); 
}); 
</script> 

<body> 
<table> 
<tr> 
<td>Email Id:</td> 
<td> 
<input type=’text’ name=」emailID」 id=」emailId」 value=」」></td> 
</tr> 
<tr> 
<td><input type=」button」 name=」Save」 id=」Save」 value=」Save」></td> 
</tr> 
</table> 
</body> 
</html> 

更多點擊。

http://www.delhincrjob.com/blog/how-to-get-the-parent-window-element-value-in-popup-window-using-jquery/