 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 12th, 2005, 08:18 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Return Value from showmodaldialog
hi !
Can some body provide me with sample code for the following scenerio ?
I have 2 textboxes and enter values in them in showmodaldialog.
I need to take these values and display them in the parent window's fields.
How do I achieve the same using window.returnvalue ?
Sanya Narayan
|
|

March 12th, 2005, 10:11 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
When you call showModalDialog you do this:
Code:
var oReturnValue = showModalDialog(....);
Within showModalDialog, assuming your textboxes have IDs of "txtForename" and "txtSurname":
Code:
<body onbeforeunload="terminate();">
function terminate()
{
var o = new Object();
o.forename = document.getElementById("txtForename").value;
o.surname = document.getElementById("txtSurname").value;
window.returnValue = o;
}
Then continuing in your main window:
Code:
alert(oReturnValue.forename + "\n" + oReturnValue.surname);
--
Joe ( Microsoft MVP - XML)
|
|

December 15th, 2006, 07:51 PM
|
|
Registered User
|
|
Join Date: Dec 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Check the following code. i have tested it and it is working fine.
On your Main Page(Parent Page), call showModalDialog as:
<script type = "text/javascript">
function Open()
{
var Return;
Return = window.showModalDialog("ChildForm.aspx", "", "dialogWidth:670px;dialogHeight:600px;")
document.getElementById("txtFirstName").value = Return.firstname;
document.getElementById("txtLastName").value = Return.lastname;
}
</script>
where Open() will invoke, upon onclick event of a button, like,
btnOpen.Attributes.Add("onclick", "Open()");
and what will you do in your Child page, is:
<script type = "text/javascript">
function Close()
{
window.close();
}
function OK()
{
var vReturnValue = new Object();
vReturnValue.firstname = document.getElementById("txtFirstName").value;
vReturnValue.lastname = document.getElementById("txtLastName").value;
window.returnValue = vReturnValue;
window.close();
}
</script>
which also will work on click event of buttons(in my case, i have used two buttons, OK and CANCEL), like,
btnOK.Attributes.Add("onclick", "OK()");
btnCancel.Attributes.Add("onclick", "Close()");
Hope it will work for you. let me know in case of any issue.
|
|

December 16th, 2006, 05:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
If you do it like that you need to test the reurnValue to make sure it's not null which can happen if someone closes the modal dialog using a method other than the prescribed button, ALT+F4 for example.
--
Joe ( Microsoft MVP - XML)
|
|

November 25th, 2009, 12:22 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi
i am newbee to this forum
my problem is also same
above code given by rohit sharma is not working for me
i am unable get values from modaldialog to parent
plz help
|
|

November 25th, 2009, 12:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
I suggest you post a small reproducible example of what's not working so we can try it ourselves.
|
|

November 25th, 2009, 01:41 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
actually this is the scenario
user should enter a value 2 times, after his first entry i dump that in to database and redirect to new page for 2nd entry. At 2nd entry it shud compare it with first entry, if it false then it shud popup with modal dialog showing first and second entry and asking him for correct entry and that value shud be passsed to 2nd entry page and that value be assigned to textbox value here I was able to do up correct entry but I was not able to pass correct entry textbox value from modal dialog to 2nd entry page textbox value
here is the code
"parent_args.html"
Code:
<html>
<head>
<title></title>
<script type="text/javascript">
function fnLaunch()
{
var aForm;
aForm = oForm.elements;
var myObject = new Object();
myObject.firstName = aForm.entry2.value;
// The object "myObject" is sent to the modal window.
window.showModalDialog("child_args.html", myObject, "dialogHeight:300px; dialogLeft:200px;");
}
</script>
</head>
<body>
<form id= "oForm" action="">
<input type="text" name="entry2" id="entry2" value="" maxlength="4" onchange="fnLaunch();" />
<br/>
</form>
</body>
</html>
"child_args.html"
Code:
<html>
<head>
<script>
var oMyObject = window.dialogArguments;
var sFirstName = oMyObject.firstName;
var sLastName = oMyObject.lastName;
function OK()
{
var Correct_Entry = document.getElementById("correct_entry").value;
var Confirm_Entry = document.getElementById("confirm_entry").value;
if (Correct_Entry == Confirm_Entry )
{
var vReturnValue = new Object();
vReturnValue.entry2 = document.getElementById("correct_entry").value;
window.returnValue = vReturnValue;
window.close();
}
else
{
alert ("comparision failed");
}
}
</script>
<title>Untitled</title>
<style type="text/css">
<!--
.style1 {
color: #000000;
font-weight: bold;
}
.style6 {color: #000000; font-size: 14px; }
.style14 {color: #000000; font-weight: bold; font-size: 14px; }
.style15 {font-size: 14px}
-->
</style>
</head>
<body style="font-family: arial; font-size: 14pt; color: Snow; ">
<table height="140" border="1" align="left">
<tr>
<td width="105"><span class="style14">Marks Entry 1 </span></td>
<td width="68"><span class="style15">
<div align="center"><span class="style2"><span style="color:#FF0000">comes from database
</span></span></div></td>
<td width="167"><span class="style14">Marks Entry 2 </span></td>
<td width="61"><span class="style15"><span class="style2"><span style="color:#FF0000"><script type="text/javascript">document.write(sFirstName);</script>
</span></span></td>
<td width="216"><span class="style14">Enter Correct Entry </span></td>
<td width="179"><span class="style15">
<input type="text" id="correct_entry" name="correct_entry" >
</span></td>
</tr>
<tr>
<td height="29" colspan="4"><span class="style15"></span></td>
<td><span class="style14">Confirm Again </span></td>
<td><span class="style15">
<input type="text" id="confirm_entry" name="confirm_entry" >
</span></td>
</tr>
<tr>
<td colspan="4"><span class="style15"></span></td>
<td colspan="2"><span class="style6">
<input name="button" type="button" class="style1" value="-----OK-----" onClick="OK();" >
</span></td>
</tr>
</table>
</body>
</html>
|
|

April 8th, 2012, 03:47 AM
|
|
Registered User
|
|
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, It Worked For Me
|
|
 |