Holding data between form posts

Posted on 2004-10-07
Last Modified: 2013-12-25
Hey guys,

I have a page that contains a number of dropdowns and text boxes
Two of the dropdowns interact with each other i.e. Dropdown one controls the content of dropdown two. [This content is read from a Sybase database]

I have done this using javascript and here is a code snippet

#CGI bit
my $co = new CGI;
my $currenturl = $co->url;
$co->popup_menu( -name=>'project',
                 -values=>['', 1,2,3],

#javascript bit
function GetSubComponents(url,projectid){
var urlTo;
if(projectid < 1)
     urlTo = url;
     urlTo = url + "?ProjectID="+projectid;
window.location.href = urlTo;

when the page is reloaded it checks the ProjectID parameter and changes the content of the second dropdown.

this stuff works fine the only problem is I need to keep the data that was on the page prior to the page being redirected.
How do I do this?

Question by:VincentLawlor
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Levan_Kiladze earned 500 total points
ID: 12257164
you can do it using cookies..
in CGI bit edit this way:
#CGI bit
my $co = new CGI;
my $currenturl = $co->url;
$co->popup_menu( -name=>'project',
                 -values=>['', 1,2,3],
                 -onchange=>"GetSubComponents('$currenturl',this.value); SaveData()",                

now in JAVASCRIPT bit add function like this:
function SaveData()

function SetCookie(cookieName,cookieValue,nDays)
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();

function GetCookie(cookiename)

 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return "";
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length;
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));

function getvalue()
      if(GetCookie(document.forms[0].project) != "")
         document.forms[0].project.selectedIndex = GetCookie(document.forms[0].project);


// ----------------------------------------------------

finally, add onload event in <body> TAG..
<body onload=getvalue()>

the second way of solving your problem is using hidden fields in your form, which stores selected index.
LVL 51

Expert Comment

ID: 12312862
> .. I need to keep the data that was on the page prior to the page being redirected.
which data?
wher do you need it?

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Identify two keyboard codes and how to enter them 9 84
Need help Creating PowerShell Script 5 81
Where to download python requests library 6 105
BatchFile-Disk Detection 23 54
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to count occurrences of each item in an array.

734 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