Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Set focus on parent form field upon child close

Posted on 2003-02-28
5
Medium Priority
?
1,448 Views
Last Modified: 2012-08-13
Hi,

I've created a form that generates a conditional popup with a "Close" button.  When I click close, I want the popup to close and the focus to be set on a particular control on the parent form.  The best I seem to be able to do is return focus to the parent window, but I can't figure out the proper commands/syntax to set the focus in any of the form controls in the parent window.  Clicking the Close button calls the following function:

<!-- Begin
function closefocus()
{
window.opener.focus();
window.close();
}
//-->

I need to set focus to window.document.Form1.Q9.

Thanks!!
0
Comment
Question by:SkibJr
  • 3
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 8043679
<!-- Begin
function closefocus()
{
window.opener.document.Form1.Q9.focus();
window.close();
}
//-->
0
 

Author Comment

by:SkibJr
ID: 8057744
Hi Zvonko,

Thanks for the reply, but I've tried this.  The popup doesn't close, indicating a problem with the previous line. If you can send me code for a specific example where you can (1) call a popup window from a parent form and then (2) close the popup, and (3) return focus to a specific field on the parent form, I'd be happy to award you the points.  
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 400 total points
ID: 8057961
Ok, see where the cursor is blinking after the popup disappear:

<html>
<head>
<script>
function callPopup(){
  nw=window.open('','newWindow','height=200,width=600,status');
  nw.document.write('<html><head><sc'+'ript>'+
'\n<!-- Begin\n'+
'function closefocus() '+
'{'+
'window.opener.document.Form1.Q9.focus();'+
'window.close();'+
'}'+
'\n//-->\n'+
                    '</sc'+'ript></head><body><form>\n'+
                    '<input type=text name=P1 onBlur="opener.document.Form1.Q1.value=this.value">\n'+
                    '<input type=button value=Close onClick="closefocus()">\n'+
                    '</form></body></html>');
}
</script>
</head>
<body>
<form name=Form1>
Q1: <input type=text name=Q1>
Q2: <input type=text name=Q2>
Q3: <input type=text name=Q3>
Q9: <input type=text name=Q9>
Q10: <input type=text name=Q10>
<hr>
<input type=button value=Popup
onClick="callPopup()">
</form>
</body>
</html>

0
 

Author Comment

by:SkibJr
ID: 8059202
Hey Zvonko,

Thanks for your help! My problem turned out to be not that I was using wrong code, but FrontPage 2000 was removing my form name (working around FP webbots can be a real pain)!  When I modified your code to:

window.opener.document.forms[0].Q9.focus();

everything worked fine.  Thanks again!!

SkibJr
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8059317
You are welcome :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question