Solved

Pass selected dropdown menu option to CGI program

Posted on 2004-09-07
9
360 Views
Last Modified: 2013-12-25

I have the following dropdown menu and numerous other input fields (regular and hidden). I am trying to figure out how to pass all the values in this form to the page that is selected from this dropdown (see code below). Currently, when an option is selected, the link to the selected page works, however, no parms get passed.

The receiving program is a CGI program. I have done this elsewhere on the page with a simple text link by calling a Javascript program and passing the value from a table row to a function call in the header.

But how do you pass the value from a dropdown such as this one?

<FORM name="SPSFS02" ACTION="./SPSFS02" METHOD="POST">

<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0 VSPACE="0" HSPACE="0" WIDTH="100%">
<tr>
 <td width="40%"><b><font size=3>Shipping Fulfillment Schedule</font></b></td>
 <td width="40%"><b><font size=3>Gypsum Board - United States<font size=3></b></td>
 <td width="20%" border=1>
    <select name="DDmenu" onChange="location=this.options[this.selectedIndex].value;">
    <option selected>Site Navigation</option>
    <option value="./SPSFS02">Region
    <option value="./SPSFS01">Plant
    <option value="./SPSFS03">SalesRep
    </select>
 </td>
</tr>
</table>
0
Comment
Question by:BPBEE
  • 3
  • 2
9 Comments
 

Author Comment

by:BPBEE
ID: 11998203
Here are examples of my existing Javascript function calls:

<script language="JavaScript">
function callapgm() {
document.SPSFS02.action = '/BPBCON/SPSFS02';
document.SPSFS02.method = "POST";
document.SPSFS02.submit();
return false;
}
function callbpgm(region,plant,fdate,tdate) {
document.SPSFS02.DXREGION.value  = region;
document.SPSFS02.DXPLANT.value  = plant;
document.SPSFS02.DXFDATE.value  = fdate;
document.SPSFS02.DXTDATE.value  = tdate;
document.SPSFS02.action = '/BPBCON/SPSFS07';
document.SPSFS02.method = "POST";
document.SPSFS02.submit();
return false;
}
function gotoURL(URL) {
document.SPSFS02.action = URL;
document.SPSFS02.method = "POST";
document.SPSFS02.submit();
return false;
}
</script>
.....
.....

<tr>
<td><a href="/BPBCON/SPSFS07" onClick="return callbpgm('P00','CG','2004-09-07-00.00.00.000000','2004-09-07-00.00.00.000000')">Northeast</td>
<td width="12%" border=1>CODY PLANT                              </td>
<td width="11%" border=1>Truckloads</td>
<td width="11%" border=1>Prepaid</td>
<td width="11%" border=1>09/07/2004</td>
<td width="11%" border=1>.00</td>
<td width="11%" border=1>0</td>
<td width="11%" border=1>0</td>
<td width="11%" border=1></td>
</tr>
.....
.....

<input type="hidden" name="DXREGION" value= " "></INPUT>
<input type="hidden" name="DXPLANT" value= " "></INPUT>
<input type="hidden" name="DXFDATE" value= " "></INPUT>
<input type="hidden" name="DXTDATE" value= " "></INPUT>
<input type="hidden" name="BPBUSER" value= "james"></input>
0
 
LVL 14

Expert Comment

by:ziffgone
ID: 12002837
Might have to pass through URL:

<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0 VSPACE="0" HSPACE="0" WIDTH="100%">
<tr>
 <td width="40%"><b><font size=3>Shipping Fulfillment Schedule</font></b></td>
 <td width="40%"><b><font size=3>Gypsum Board - United States<font size=3></b></td>
 <td width="20%" border=1>
    <select name="DDmenu" onChange="chgLoc(this.options[this.selectedIndex].value);">
    <option selected>Site Navigation</option>
    <option value="./SPSFS02">Region
    <option value="./SPSFS01">Plant
    <option value="./SPSFS03">SalesRep
    </select>
 </td>
</tr>
</table>
 

Then assign a bunch of variables with the values you wish to pass:

JAVASCRIPT CODE:

function chgLoc(page){
        var val1 = document.form_name.field1.value;
        var val2 = document.form_name.field2.value;
        var val3 = document.form_name.field3.value;
        // etc for each value you want to pass to the next page

        // now time to go to the page:

       window.location = page+"?val1="+val1+"&val2="+val2+"&val3="+val3;
}

Then, in the receiving page (CGI I'm assuming):

CGI/PERL CODE:
use strict;
use CGI;

my($val1,$val2,$val3,$val4);
$val1 = "";
$val
if(param('val1')){
     $val1 = param('val1');
}
if(param('val2')){
     $val2 = param('val2');
}
if(param('val3')){
     $val3 = param('val3');
}
etc...

then:
HTML CODE:
print '<input type="text" name="val1" value="'.$val1.'">';

or

print <<ENDHTML;

<select>
       <option value="$val">$val</option>
</select>
ENDHTML
etc.

You'll have to edit things to suit your needs.

Hope that helps.

Regards...
0
 
LVL 14

Accepted Solution

by:
ziffgone earned 500 total points
ID: 12002850
Sorry, error in code:

This,
my($val1,$val2,$val3,$val4);
$val1 = "";
$val
if(param('val1')){
~

Should've been this:
my($val1,$val2,$val3,$val4);
$val1 = "";
$val2 = "";
$val3 = "";
etc.

if(param('val1')){
~

Regards...
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 2

Expert Comment

by:mishagale
ID: 12007610
try replacing your onChange code with "document.SPSFS02.action=this.options[this.selectedIndex].value;"

0
 
LVL 2

Expert Comment

by:mishagale
ID: 12007653
sorry, amend that to:
"document.SPSFS02.action=this.options[this.selectedIndex].value; document.SPSFS02.submit();"
0
 
LVL 2

Expert Comment

by:mishagale
ID: 12200037
LearnedOne: I think that ziff's was probably the better solution, taking into account the existing code from the questioner. I suggest awarding the points to ziffgone.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.

810 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