Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:16:27+00:00 2026-06-02T05:16:27+00:00

I am creating a web page that has 3 basic elements, select box, button,

  • 0

I am creating a web page that has 3 basic elements, select box, button, & table. From a high level, the user selects an element, and clicks the button. When the button is clicked, a PERL script is executed that puts data in a table in a mySQL db. All those things work successfully.

Now, I am trying to return the DB table values to my HTML file with a dynamic table. But every source I find has my CGI file writing html tags. I don’t feel this is right, because I don’t understand home my CGI knows the table ID, even though I am passing the value. Also, I know my js file is incorrect, having two separate AJAX calls, but that is home I am logically processing in my head.

I am not sure what comes first, fixing the CGI or JS file.

HTML Code (index.html):

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js" charset="utf-8"></script>
        <script type="text/javascript" class="jsbin" src="C:/xampp/DataTables/media/js/jquery.dataTables.js" charset="utf-8"></script>
        <script type="text/javascript" src="js/main.js" charset="utf-8"></script>
        <script type="text/javascript" src="js/RunPerlScript.js" charset="utf-8"></script>
        <script type="text/javascript" src="js/table.js" charset="utf-8"></script>
    </head>
    <body>
        <header>
            <h1></h1>
        </header>
        <form name="myForm" method="GET" action="">
            <select id="cdLDAP" >
                <option/>
            </select>
            <input type="button"  id="btn_run" name="btn_run" value="Run"></input>
        </form>
        <table id="results_table">
            <thead>
                <tr>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

Perl (CGI):

 #!/usr/bin/perl -T
    use CGI;
    use DBI;
    use strict;
    use warnings;

    # read the CGI params
    my $cgi = CGI->new;
    my $inputselection = $cgi->param("cdLDAP");
    my $html_table = $cgi->param("html_table_results");
    my ($base_dn, $tblname);
    #my $password = $cgi->param("password");

    #my $inputselection = "Disabled Users";
    #LDAP Connection parameters
    if ($inputselection eq "Disabled Users") {
        $base_dn = "";
        $tblname = "disabled_user";
    } elsif ($inputselection eq "") {
        $base_dn = "";
        $tblname = "service_account";
    } elsif ($inputselection eq "") {
        $base_dn = "";
        $tblname = "";
    } else {
        die;
    }

    # connect to the database
    my ($platform,$database,$host,$port,$db_user,$pw) = ("mysql","results","localhost","3306","resultsuser","mysql123");
    my $dsn = "DBI:$platform:database=$database,host=$host,port=$port";
    my $connect = DBI->connect("DBI:mysql:database=$database;host=$host",$db_user,$pw,{RaiseError => 1});

    #query db to get results set for table output
    my $query_results = "SELECT * FROM " . $tblname;
    my $query_handle = "";
    $query_handle = $connect->prepare($query_results) or die $connect->errstr;
    $query_handle->execute() or die $query_handle->errstr;

    print header;
    # HTML for the beginning of the table
    # we are putting a border around the table for effect
    print "<table border=\"1\" width=\"800\"> \n";

    # print your table column headers
    print "<tr><td>User ID</td><td>Status</td><td>Last Password Reset</td><td>Reset Needed?</td></tr>\n";

    my (@data,$uid,$status,$pwlstset,$resetmsg);

    # retrieve the values returned from executing your SQL statement
    foreach (@data = $query_handle->fetchrow_array()) {
    $uid = $data[0];
    $status = $data[1];
    $pwlstset = $data[2];
    $resetmsg = $data[3];

    # print your table rows
    print "<tr><td>$uid</td><td>$status</td><td>$pwlstset</td><td>$resetmsg</td></tr>\n";

    }

    # close your table
    print "</table>\n";

    # exit the script
    exit;

JS/JQuery/AJAX:

$(function() {
    $('#btn_run').click(function() {
        var tblname = $('#cdLDAP').val();
        var html_table = $('#results_table').attr('id');
        $.ajax({
            type: "GET",
            url: "/perl/cgitest.pl", // URL of the Perl script that queries LDPA and inputs to mySQL
            data: "cdLDAP=" +tblname,
            // script call was *not* successful
            error: function() { 
                alert("ERROR!");
            }, // error 
            // script call was successful 
            // data contains the JSON values returned by the Perl script 
            success: function(data){
                alert("success!");
            } // success
        }); // ajax
        $.ajax({
            type: "GET",
            url: "/perl/cgitest2.pl", // URL of the Perl script that retirves data from mySQL
            data: "cdLDAP=" +tblname +",html_table_results=" +html_table,
            // script call was *not* successful
            error: function() { 
                alert("ERROR!");
            }, // error 
            // script call was successful 
            // data contains the JSON values returned by the Perl script 
            success: function(data){
                alert("success!");
            } // success
        }); // ajax
    });
});

So here is what I need some help with:
1) Should my PERL script be writing the html tags? If yes, how do I write to index.html and not a new html file?
2) If the table structure is created by the jquery file, a good teaching source would eb appreciated, because I am trying to be taught how to fish, and not given a fish.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:16:30+00:00Added an answer on June 2, 2026 at 5:16 am

    Should my PERL script be writing the html tags?

    There is no such thing as PERL.

    If you want to use Ajax to dynamically update a page (note that you should be using unobtrusive JavaScript) then there are two basic approaches you can take:

    1. Server returns data in a clean data structure (possibly JSON)
    2. Server returns a fragment of HTML

    I’m generally in favour of the former approach (in which case you would construct an array of hashrefs in your Perl, run it through a JSON module and then output it with an application/json Content-Type HTTP header.

    Given that some versions of Internet Explorer have problems with trying to edit the innerHTML of a table element, this makes the first option better.

    If yes, how do I write to index.html and not a new html file?

    You don’t write to a file at all. You return the data via STDOUT and the webserver passes it back to the client.

    If the table structure is created by the jquery file, a good teaching source would eb appreciated

    http://api.jquery.com/category/manipulation/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a page that has some dynamically generated images built from data that
I'm creating a web server control that has an image button on it. The
I am creating an iOS web app that has a fixed div (say 200px
I'm creating a very simple chat application. It has an ASP.NET web page as
I have a web page that has a few text boxes, and a dual
I use Asp.NET Mvc 3 for creating web page and so I detect that
I am creating a web page which will have a Select element with a
I'm creating a form on a web page, but I want that form to
I am creating web page using asp.net. Is it possible to remove/hide the browsers
I'm creating a web page, and I can't (with html code) add a draw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.