• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

resubmitting a form based on input from another window

I have a script that prints out a html page.  The user will input values and then submit the form. If certain criteria is not met, a pop-up window is then opened and the user must select a radio button and send that value back the originating page. Now the originating page(the script) must be re-run with the value from the pop-up window and all the calculations must be re-done.  I pass the value of the radio button the first page through a hidden field but when I re-submit the page, all the user-entered values are gone and the hidden-field value is undefined.  How do I keep the values there while re-calculating with the value submitted from the pop-up window ????

Here is some of the code for the script:
#!/usr/local/bin/perl

require 'header.pl';
require 'msc.pl';
require 'timelocal.pl';


&header("FAX-PRQ","Purchaser Pre-Qualification","faxprq");
&ReadPost(*inputs);

# PAT
$percent = 0;
$errmsg = "";

if ($inputs{"Submit"})
{
#OTHER CALCULATIONS DONE HERE

  $ceiling = $inputs{"test"};
  if ($percent <= 5)
  { if ($ceiling == 0)
    { $errmsg .= "You must select a Home Price Ceiling for your area.<br>";

# THIS IS WHERE I OPEN THE POP-UP WINDOW IF IT IS NEEDED
      print '<SCRIPT LANGUAGE="Javascript">',"\n";
    print 'window.open("/help/ceiling.html", "Ceiling_Price_List", "scrollbars=yes,width=450,height=300");',"\n";
    print "</SCRIPT>\n";
      $was_below_five = 1;  
      $highest = 0;
    }  

print "<FORM NAME=Form1 action=",$CGI_BIN,"/prq.pl method=POST>\n";

#THIS IS THE HIDDEN FIELD
print "<INPUT TYPE=TEXT NAME=test VALUE=$ceiling>\n";

print "<P><TABLE BORDER=0 cellpadding=3><tr bgcolor=#eee5ca>\n";

#TEXT FIELDS WHERE USER INPUTS INFO
print "<tr bgcolor=#eee5ca>\n";
print "<td colspan=6>";
print '<input type=submit name=Submit value="Calculate Qualification">',"\n";
print '<input type=submit value="Clear Form">',"\n";
print "</table>\n";
print "</FORM>\n";
print "</CENTER>\n";

This is the code for the pop-up window:

<HTML><HEAD>
<TITLE>Home Price Ceiling List</TITLE>
<SCRIPT LANGUAGE="Javascript">
function byebye()
{  window.close();
}
</SCRIPT>
</HEAD>
<BODY bgcolor="#FFFFFF" text="#000000">
<FORM METHOD=POST onSubmit="opener.document.Form1.test.value = this.rb.value;byebye();opener.document.Form1.submit();">
<P><FONT SIZE=2>Since your down payment was 5% or less than the purchase price, you will
need to choose a ceiling that applies to your area.  To select, click on the button with the Code
number associated with your area and click on Send.</FONT>
<TABLE>
<TR><TH>Municipality</TH>
<TH>Ceiling</TH>
<TH>Code</TH>
<TD COLSPAN=2></TD>
<TH COLSPAN=3>Press Price Ceiling Code</TH></TR>
<TR><TD>Metro Toronto(All)</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD><TD COLSPAN=2></TD>
<TD ALIGN="CENTER"><INPUT TYPE=RADIO NAME=rb VALUE=1>1</TD>
<TD ALIGN="CENTER"><INPUT TYPE=RADIO NAME=rb VALUE=2>2</TD>
<TD ALIGN="CENTER"><INPUT TYPE=RADIO NAME=rb VALUE=3>3</TD></TR>
<TR><TD>Peel Region(All)</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD>
<TD COLSPAN=3></TD><TD ALIGN="CENTER"><INPUT TYPE=SUBMIT NAME=Submit VALUE="Send"></TD></TR>
<TR><TD>York Region(All)</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD>Halton Hills</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD>Milton, Oakville</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD>Ajax, Pickering</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD>Scugog, Uxbridge</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD>Orangeville</TD><TD>$250,000</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD>Oshawa</TD><TD>$175,000</TD><TD ALIGN="CENTER">2</TD></TR>
<TR><TD>Hamilton</TD><TD>$175,000</TD><TD ALIGN="CENTER">2</TD></TR>
<TR><TD>Barrie</TD><TD>$175,000</TD><TD ALIGN="CENTER">2</TD></TR>
<TR><TD>Most Other Centres</TD><TD>$125,000</TD><TD ALIGN="CENTER">3</TD></TR>
</TABLE></FORM></BODY></HTML>
0
arjang070898
Asked:
arjang070898
  • 3
  • 2
1 Solution
 
alamoCommented:
There are two problems I see.

First is really a javascript problem - "this.rb.value" really is undefined. Try alert(this.rb.value); in the onSubmit to see this.

This happens because each radio button is a a separate object, so you can't say "this.rb.value". The easiest solution is to change the radio buttons to something like:

<INPUT TYPE=RADIO NAME=rb VALUE=3  onClick="opener.document.Form1.test.value=3">3

This way when the user selects a radio button the value in the opener form will be set, you won't have to do it in your form onSubmit.

The second problem - the values from your original form being missing - isn't clear because you cut all that code out of your exanmple. In general, though, you need to explicitly set the starting values of the input elements to their values from the previous form, it doesn't happen automatically. For example,

print "<INPUT TYPE=text NAME=lastname VALUE=\"$inputs{lastname}\">";

The " " around the value is needed in case $inputs{lastname} has a space in it.

Hope this helps, good luck!
0
 
sybeCommented:
onClick="opener.document.Form1.test.value=3"
will only work when you open the popup with something like:
PopUp = window.open("/help/ceiling.html", "Ceiling_Price_List", "scrollbars=yes,width=450,height=300"

This makes it possible to refer back to the opener
0
 
alamoCommented:
Ok, yes, but that's how the popup *is* opened in the arjang's example script... I'm not sure I see your point.
0
 
sybeCommented:
alamo: the point is that you can't link back to the opener when it is not a variable in the original document.
0
 
alamoCommented:
Sorry, you have lost me... are you saying assigning the value of window.open to a variable (PopUp in your example) is necessary? It works fine without it in Netscape and IE. The variable is only necessary when referring to the popup from the main page, not when referring to the main page from the popup.

arjang's original code worked perfectly in both NS and IE when it came to setting the value in the main form from the popup. The value was wrong, but it was was being passed properly to the main form..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now