?
Solved

Set focus on parent form field upon child close

Posted on 2003-02-28
5
Medium Priority
?
1,286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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

752 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