CGI / Frames question

Sandy Norton sandskyfly at hotmail.com
Mon Aug 19 23:13:33 EDT 2002


Paul Rubin wrote in message:
> sandskyfly at hotmail.com (Sandy Norton) writes:
> > What I specifically would like to do is have the user click on
> > 'submit_b' from the control frame (control.html) and pass on the
> > differences in state from _both frames_ to the python cgi script. It
> > would be as if both 'submit_a' and 'submit_b' were somehow pressed
> > simultaneously.
> > 
> > Is this possible?
> > 
> > Any help would be much appreciated,
> 
> Simplest way is with client side javascript, I'll leave the details to you.

I suspected as much before and your pointer confirmed this to me... 
Following your advice I did a bit of digging through javascript and
found a way to do it (-:


frame.html
----------
<frameset rows="*,45" frameborder="NO" border="0" framespacing="0"
cols="*">
  <frame name="contentFrame" src="content.html">
  <frame name="controlFrame" scrolling="NO" noresize
src="control.html">
</frameset>


interframe.js 
-------------
function getElements(es) {
    s = "";
    for (var i=0; i < es.length; i++) {
        if (es[i].checked)
            s += es[i].name + ":" + es[i].value + " | ";
    }
    return s;
}
function sendForm() {
    if (parent.contentFrame.document.contentForm) {
        var es = parent.contentFrame.document.contentForm.elements;
        parent.controlFrame.document.controlForm.articles.value =
getElements(es);
    }
}

control.html
------------
<script language="JavaScript" type="text/javascript"
src="interframe.js"></script>
<form 
    name="controlForm" method="get" action="cgi-bin/testcgi.py" 
    target="contentFrame" onsubmit="sendForm()"
>
    <input type="submit" value="go">
    <input type="hidden" name="articles">
</form>

content.html
------------
<form action="cgi-bin/testcgi.py" method="get" name="contentForm">
    <input type='checkbox' name='field1' value="a"> <a
href='http://www.news.com/story1.html'>article 1</a>
    <input type='checkbox' name='field2' value="b"> <a
href='http://www.news.com/story1.html'>article 2</a>
    <input type="submit" name="submit_a" value="go">
</form>



----------------------------------------------------------------------
Basically you convert all the data you want from the content frame's
form into a string, and then pass it into a hidden input var in the
control frame's form which is subsequently to a cgi script after a
submit.

Incidentally, client-side javascripting was truly a PIT. (I am truly
spoilt by python's introspective qualities.)

Back to some fun code now...


Ciao,


Sandy



More information about the Python-list mailing list