Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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
 
Old December 29th, 2003, 08:58 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default display value from opened window

I want to display the value selected in the specat to be displayed on textbox in salesreport.html. Below are my code, and it's not working. Please correct my code.
Besides, i would like to know if i could put two function in the onclick like catsubmit button below?

//salesreport.html
<form name="myform>
<input type="radio" name="view_by" value="overall">Overall<br>
<input type="radio" name="view_by" value="category">View Category<br>
<input type="radio" name="view_by" value="specategory" onclick="window.open('chosecat.html', 'mywindow', 'height=100, width=400')">View Specified Category<br>
<input type="text" name="text1" value="name">

//chosecat.html
<script type="text/javascript">
function function1()
{
        document.myform.text1.value = specat;
 }
</script>

<select name="specat">
    <option>category1</option>
    <option>category2</option>
    <option>category3</option>
    <option>category4</option>
    <option>category5</option>
</select>
<input id="but1" type="submit" name="catsubmit" value="OK" onclick="function1(), self.close()">
<input id="but2" type="button" name="btncancel" value="CANCEL" onclick="self.close()">

 
Old December 29th, 2003, 03:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

To refer to the window that opened the window you are in, you will need to use the OPENER object, so your code becomes :

opener.document.myform.text1.value = specat;

You may also need to expand the specat call to be a full path to the field to support all browsers.

 
Old December 29th, 2003, 07:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hosefo81,

In addition to what Greg said:

I am not sure if your script is a direct quote, but if it is, you forgot to close the name attribute quotes...

Code:
<form name="myform">
I don't know if this is simply a typo from when you posted the message, but if not, this should help you a great deal.

Snib

 
Old December 30th, 2003, 01:27 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Snib! <form name="myform"> is a typing error so that's not the problem.i've changed
function function1()
{
        opener.document.myform.text1.value = specat;
}

but nothing happens. The value is not displayed and the window is not closed. What's the problem?

besides, what is greg means by "expand the specat call to be a full path to the field to support all browsers".


 
Old December 30th, 2003, 03:48 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hosefo81,

I think what Greg is saying is that instead of refering to the select menu simply by the name, you need to attach the path to the beginning.

Also, to gain a value from the select menu, you must have a value attribute on each option tag.
Code:
// using getElementById()...
opener.document.forms.myform.text1.value = document.getElementById("specat").options[document.getElementById("specat").selectedIndex].value;

// give ID attribute and value attributes...
<select id="specat">
<option value="value1">1</option>
<option value="value2">2</option>
</select>
HTH

Snib





Similar Threads
Thread Thread Starter Forum Replies Last Post
access opener window's elements in opened window hafizmuhammadmushtaq Javascript 3 April 8th, 2008 01:43 AM
How to display image in a pop-up window nrlahoti ASP.NET 2.0 Professional 1 October 15th, 2007 07:28 AM
closed parent window when opened child window jaiwin Javascript How-To 0 October 8th, 2006 12:54 PM
Display DB Window problem bradles Access 5 March 4th, 2004 06:34 PM
Can't display a bitmap in a window drb2k2 C++ Programming 1 September 3rd, 2003 04:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.