Must populate a select box onClick

Posted on 2003-03-19
Medium Priority
Last Modified: 2013-12-25
I have dynamically loaded select boxes in a for loop. When the page first loads the select boxes should be empty because we dont want them all to load info from the DB at the same time. However, when any of the boxes is clicked on I need it to reload them populated with options.
How would I go about doing this?
Below is the simple code for how I print my select boxes. But Not sure how to reload them. I also included the function that populates the select box with options, but it doesn't work. Please, help.  

Loop2 : for($i =1; $i <= $MaximumColumn; $i++){
   if  ($result eq "") {
      if ($Updatable == 1) {
           print ("<td height='5' width='500'>Value Not Assigned$tdcls<td><select          name='$selectedAttr' dir=\"rtl\" width=\"20\" onclick=\"javascript: PopulateSelectBox($selectedAttr)\"></td></tr>");                                                          }else {
         print "<td height='5' width='600'>Value Not Assigned</td></tr>";

sub PopulateSelectBox(selectedAttr){
     #print("Inside Populate SelecBox");
     $sqlCmd2 = "select distinct $selectedAttr from RiskXpress order by $selectedAttr ";
          @AttributePickList = &sql($dbpr,$sqlCmd2);
          #print("Inside Populate SelecBox2");
          L1: foreach $line (@AttributePickList) {
               $line =~ s/ *~ */~/g;
               ($Value) = split(/~/,$line);
               if (!$Value){next L1;}
                $Value = rm_junk_char_display($Value);
                print("Inside Populate box3");          
                print "<option value=\"$Value\">$Value</option>";
Question by:mr33819
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

elcamello earned 100 total points
ID: 8181508
I assume the select box is embedded in an HTML FORM.

The first time the page is loaded, you would have to replace:
onclick=\"javascript: PopulateSelectBox($selectedAttr)\">

by a javascript function call that changes the FORM action to something like PopulateSelectBox.cgi?selectname=SOMENAME, and then submit the form.

Within PopulateSelectBox.cgi, you can invoke your
 sub PopulateSelectBox(selectedAttr){
with the selectedAttr argument equal to (e.g.) SOMENAME, which will print the necessary HTML code to construct your select box. Of course, this time around you should not define the same onclick action for your select box, otherwise when attempting to select an option, the form will be re-submitted etc.

Hope this helps.

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 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