By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Problem with form variables in frames

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a

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

P: n/a

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.