Click to See Complete Forum and Search --> : Setting form targets


jovialjonny
06-09-2003, 11:12 AM
Hey,
I have a form in an HTML page that is being submitted to a servlet like so:
<form id= "form" action="viewerServlet">

I want to target the response of the servlet to an iframe in a child page. Right now I am doing this like so:

/* 'viewer' is a child page that has been opened. Its method 'createTab()' returns the id of the frame that I want the results of the form displayed in*/

var frameId = viewer.createTab();
//'form' is the form I created above.
form.target = frameId;

But this isn't working. The servlet keeps opening a new page instead of loading the new page into the specified iframe like I want it to.

Does anyone know what I am doing wrong or how I can get this to work another way?

Khalid Ali
06-09-2003, 11:36 AM
Your code or question seems confusing..

I Know that if you put a target attribute in the form tag

<form...........target="someFrameName">

the servlet will respond the results to that targetd frame.

jovialjonny
06-09-2003, 11:49 AM
Well the frame I wish to send it to is actually created on the fly in the child page so I can't put it directly into the parent's HTML because it doesn't exist yet.

What I am trying to do is create the frame and then pass its id to the parent (which is working correctly), then I am using javascript to set the target of the form and then I submit the form to the servlet.

So in the parent page's HTML I have this:
<form id= "form" action="viewerServlet">
<input type="Button" onclick="openViewer()" value="Subscribe" />
</form>

The onclick method 'openViewer()' opens the child page and as soon as the child has created the iframe it returns the iframe's id to the parent so that the target can be set.
Thus in the parent's javascript file I have this code:
function addPage()
{ //'viewer' = child page, returns id of iframe
var frameId = viewer.createTab();
var form = document.getElementById("form");
form.target = frameId;
form.submit();
}

The problem is that the page does not load into the desired iframe- I think it is a referencing issue but I don't know what is the correct way to direct the form to the iframe with the id 'frameId'.
I tried to pass the iframe object itself as the target, and I tried setting the form's target to be the source (.src) of the iframe but neither worked.

Any ideas?

Khalid Ali
06-09-2003, 12:05 PM
There are things that I'd not do in your code..such as form is an html element therefore giving that an id attributes value could be a potential problem.

now as you mentioned that you have this iframe in the child window,this is how I"d do it..

myCurrentForm.target =childWin.frameName;

unless you post a real link to ur code or post your code in here or upload your code as a zip file or text file,its not easy to privide code from partial code snippests..