Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch focus to an element outside an iframe?

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Hi I have a form that has several inputs.

I have the user entering three of these to start with and then I have an OnChange="ComposeGMQ()" on the third which loads up an iFrame using the three inputs as part of its URL.

So far so good.

Now once this is done I want the focus to return to the 4th input on the original form.

My code is....
Code:
function ComposeGMQ()
{
	[blue]//get journey points...
    //convert them to UpperCase...[/blue]

	GMQ = "[URL unfurl="true"]http://maps.google.com/maps?daddr="[/URL] + 
        [blue]...the journey points and other params required by GoogleMaps
	
        //next line used to open a new browser window to display Google Maps[/blue]
	//win = window.open(GMQ, "js");
	
        [blue]//I now display this within an Iframe whoes elementID is GMA[/blue]
	document.getElementById("GMA").src= GMQ

         [red]Fine up to this point[/red]

        [blue]//if I use this line the Focus just goes to the first input box in the iFrame and not the 4th input in the form - no error given[/blue]
	document.getElementById("DistanceInput2").focus()

       [blue]//using the line below gives me an error 'is null or not and object - qquote3 is the ID for the Form and DistanceInput2 is the ID of the 4 input.[/blue]
       document.qquote3.DistanceInput2.focus()
}

I think that the iform is not finished loading and the focus is being executed.

Any help appreciated
 
Dan,

No I have made sure that the ID is unique. I have even checked the source of Google Maps page to see if they have an element id of DistanceInput2.

From the bit of tinkering I have been doing it seems that the [blue]document.....focus[/blue] command is looking within the 'document' contained within the iframe and not looking at the whole picture which is basically a document with a table. The table has a row spread across the width of the screen spanning 2 columns and contains the page title.
The next row has the 1st column at 30% and this contains a separate table containing the form qquote3. The 2nd column is set to 70% width and contains an iFrame for the Google Map page to be displayed.

If you need any more info let me know.
 
You could be right... Google may have a .focus() on their page that takes the focus back to its first input box after my comad has run.

Shame... oh well onwards and farwards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top