Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 12th, 2005, 07:18 AM
Registered User
 
Join Date: Mar 2005
Location: Mumbai, Maharashtra, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to SanyaNr Send a message via Yahoo to SanyaNr
Default 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
__________________
Sanya Narayan
Reply With Quote
  #2 (permalink)  
Old March 12th, 2005, 09:11 AM
joefawcett's Avatar
Wrox Author
Points: 9,712, Level: 42
Points: 9,712, Level: 42 Points: 9,712, Level: 42 Points: 9,712, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,066
Thanks: 1
Thanked 36 Times in 35 Posts
Default

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)
Reply With Quote
  #3 (permalink)  
Old December 15th, 2006, 06:51 PM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #4 (permalink)  
Old December 16th, 2006, 04:30 AM
joefawcett's Avatar
Wrox Author
Points: 9,712, Level: 42
Points: 9,712, Level: 42 Points: 9,712, Level: 42 Points: 9,712, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,066
Thanks: 1
Thanked 36 Times in 35 Posts
Default

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)
Reply With Quote
  #5 (permalink)  
Old November 25th, 2009, 11:22 AM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old November 25th, 2009, 11:38 AM
joefawcett's Avatar
Wrox Author
Points: 9,712, Level: 42
Points: 9,712, Level: 42 Points: 9,712, Level: 42 Points: 9,712, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,066
Thanks: 1
Thanked 36 Times in 35 Posts
Default

I suggest you post a small reproducible example of what's not working so we can try it ourselves.
__________________
Joe
http://joe.fawcett.name/
Reply With Quote
  #7 (permalink)  
Old November 25th, 2009, 12:41 PM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>
Reply With Quote
  #8 (permalink)  
Old April 8th, 2012, 03:47 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, It Worked For Me
Reply With Quote
  #9 (permalink)  
Old July 5th, 2012, 02:15 AM
Banned
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Opening a window opens it non-modal. ShowModalDialog opens it modally. Nothing more to it than that..........
Click here to obtain more information Raspberry Ketone Supplement
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
showModalDialog Problem akhilesh_g Javascript 0 July 14th, 2008 06:43 AM
ShowModalDialog DarrenMelling Javascript How-To 7 February 17th, 2005 10:59 AM
showModalDialog() leion General .NET 3 June 6th, 2004 04:08 PM
function showModalDialog cirudinezidane Javascript How-To 0 April 13th, 2004 05:24 AM



All times are GMT -4. The time now is 08:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.