468,244 Members | 1,796 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,244 developers. It's quick & easy.

Problem with form variables in frames

Hi,

I am using frames (I know that its not a good practice, but I have to).
Each of these frames have separate form variables, all of which are
needed in the parent frame.

Now, the problem is that only one frame in the parent frame has a
submit button. Is there any way in which I can submit the forms of
other frames on click of the submit of this particular frame? I mean,
is there any way in which I can access the forms in JSPs of other
frames?

Thanks.

Sep 26 '06 #1
3 1207
wrote on 26 sep 2006 in comp.lang.javascript:
I am using frames (I know that its not a good practice, but I have to).
Each of these frames have separate form variables, all of which are
needed in the parent frame.

Now, the problem is that only one frame in the parent frame has a
submit button. Is there any way in which I can submit the forms of
other frames on click of the submit of this particular frame? I mean,
is there any way in which I can access the forms in JSPs of other
frames?
What are JSPs?

You could access the other frames form values [not 'variables']
with with javascript [if they are in the same domain.]

Not tested, but try something like this:

<form onsubmit='return doit(this)'>
<input name='hidden1' type='hidden'>
</form>

.....
function doit(thisFrame){
if (!window.parent) return false;
var theOtherFrame =
window.parent.otherFrame.document;
var theOtherElement =
theOtherFrame.forms['otherForm'].elements['otherElement'];
thisFrame.elements['hidden1'].value = theOtherElement.value;
return true
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 26 '06 #2

mi***********@gmail.com wrote:
Hi,

I am using frames (I know that its not a good practice, but I have to).
Each of these frames have separate form variables, all of which are
needed in the parent frame.

Now, the problem is that only one frame in the parent frame has a
submit button. Is there any way in which I can submit the forms of
other frames on click of the submit of this particular frame? I mean,
is there any way in which I can access the forms in JSPs of other
frames?

Thanks.
Sure. Simple example looks like:

<frameset cols="50%,50%">
<frame name="frame1" src="frame1.html"/>
<frameset rows="50%,50%">
<frame name="frame2" src="frame2.html"/>
<frame name="frame3" src="frame3.html"/>
</frameset>
</frameset>

Frame1 and Frame2 look like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<form name="form1" action="http://www.google.com/">
</form>
</body>
</html>

Frame3 has the same form but with a submit button and the javascript
needed to submit all three forms at once:

<html>
<head>
<script type="text/javascript">
function updateAll() {
if (window.parent) {
window.parent.frame1.document.forms['form1'].submit();
window.parent.frame2.document.forms['form1'].submit();
document.forms['form1'].submit();
return true;
}
else {
return false;
}
}
</script>
</head>
<body>
<form name="form1" action="http://www.google.com/" onsubmit="return
updateAll();">
<input type="submit" value="Update"/>
</form>
</body>
</html>

HTH

Sep 26 '06 #3

Evertjan. wrote:
wrote on 26 sep 2006 in comp.lang.javascript:
I am using frames (I know that its not a good practice, but I have to).
Each of these frames have separate form variables, all of which are
needed in the parent frame.

Now, the problem is that only one frame in the parent frame has a
submit button. Is there any way in which I can submit the forms of
other frames on click of the submit of this particular frame? I mean,
is there any way in which I can access the forms in JSPs of other
frames?

What are JSPs?
JavaServer Pages. Server side java that results in rendered HTML
(somewhat like ASPs are to VBScript or J++).
>
You could access the other frames form values [not 'variables']
with with javascript [if they are in the same domain.]

Not tested, but try something like this:

<form onsubmit='return doit(this)'>
<input name='hidden1' type='hidden'>
</form>

....
function doit(thisFrame){
if (!window.parent) return false;
var theOtherFrame =
window.parent.otherFrame.document;
var theOtherElement =
theOtherFrame.forms['otherForm'].elements['otherElement'];
thisFrame.elements['hidden1'].value = theOtherElement.value;
return true
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rahul Chatterjee | last post: by
1 post views Thread by Ed Blinn | last post: by
1 post views Thread by Paul | last post: by
reply views Thread by John Wood | last post: by
1 post views Thread by Bill H | last post: by
2 posts views Thread by Wee Bubba | last post: by
4 posts views Thread by Harry | last post: by
1 post views Thread by gzannd | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.