Connecting Tech Pros Worldwide Help | Site Map

Problem with form variables in frames

misra.manisha@gmail.com
Guest
 
Posts: n/a
#1: Sep 26 '06
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.

Evertjan.
Guest
 
Posts: n/a
#2: Sep 26 '06

re: Problem with form variables in frames


wrote on 26 sep 2006 in comp.lang.javascript:
Quote:
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)
Tom Cole
Guest
 
Posts: n/a
#3: Sep 26 '06

re: Problem with form variables in frames



misra.manisha@gmail.com wrote:
Quote:
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

Tom Cole
Guest
 
Posts: n/a
#4: Sep 26 '06

re: Problem with form variables in frames



Evertjan. wrote:
Quote:
wrote on 26 sep 2006 in comp.lang.javascript:
Quote:
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++).
Quote:
>
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)
Closed Thread