Solved

resubmitting a form based on input from another window

Posted on 1998-07-09
5
190 Views
Last Modified: 2010-03-05
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
Comment
Question by:arjang070898
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 70 total points
ID: 1208347
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
 
LVL 28

Expert Comment

by:sybe
ID: 1208348
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
 
LVL 6

Expert Comment

by:alamo
ID: 1208349
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
 
LVL 28

Expert Comment

by:sybe
ID: 1208350
alamo: the point is that you can't link back to the opener when it is not a variable in the original document.
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208351
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now