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 6779103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:20:44+00:00 2026-05-26T16:20:44+00:00

I would like to clarify how browser scripting (such as javascript/jquery) differs from server

  • 0

I would like to clarify how browser scripting (such as javascript/jquery) differs from server side scripting (such as PHP) and how they are allowed to interact with each other.

If I have php code inside of my html code, javascript definitly can not change any of that script since its not really there. The server first reads through the php code and then sends its output (as well as any normal html code in the file) over to the web browser, so the web browser never sees all your php code. On the flip side, php can’t see the DOM because its not yet on the browser yet, and therefore be dynamic in the way javascript is. The way you make them interact is with ajax…

My question is: I have jquery ajax call which calls a php file to create a table and the table data has a link in it. Is there any reason why when I create the table from this php file that I can’t now access it through another jquery/javascript call?
This is my code:

 $(document).ready(function()
   {
        $("#build_table, .Course_Name, .Start_Date, .Book_Title, .Book_Author, .Book_Isbn").click(function()
        {
            var whichButton = $(this).attr("class");
            console.log("Whichbotton = " + whichButton);
            var prog = $("#program option:selected").text();
            var sch = $("#school option:selected").text();
            var trm = $("#term option:selected").text();
            var ext = $("#extension option:selected").text();
            if(prog == "" || sch == "" || trm == "")
            {
                alert("Please enter a selection for each field");
            }
            else
            {
                $.get("build_table.php", {program: prog, school: sch, term: trm, extension: ext, button: whichButton},
                function(table)
                {   console.log("Entered table function");
                    $("#input_table").replaceWith("<div id='input_table'>" + table + "</div>");
                });
            }   
        });
   });

and my php file snippet:

$program = $_GET["program"];
$school = $_GET["school"];
$term = $_GET["term"];
$extension = $_GET["extension"];
$button = $_GET["button"];

$con = mysql_connect("127.0.0.1","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$term = str_replace(" ", "", $term); 
$sql = "SELECT * FROM tbl_name WHERE Dep1= '" . $program . "' AND Dep2= '" . $school . "' AND Dep3 = '" . $term . "'";
if($button == "build_table")
{
//add nothing  
}
else
{   echo $button;
$button = str_replace("_", " ", $button);
$sql = $sql . "ORDER BY `" . $button . "` DESC";
}   
mysql_select_db("csv_db", $con);

$result = mysql_query($sql)  or die(mysql_error());
echo $sql;
$num_rows = mysql_num_rows($result);
echo "<br>Number of Rows: " . $num_rows; 
echo "<table id='booklist'><tr>
                         <th>Edit</th>
                         <th class='coursename'><a href='#' class='Course_Name'>Course Name</a></th>
                         <th class='startdate'><a href='#'>Start Date</a></th>
                         <th class='booktitle'><a href='#'>Book Title</></th>
                         <th class='bookauthor'><a href='#'>Book Author</a></th>
                         <th class='bookisbn'><a href='#' class='Course Name'>Book ISBN</a></th>
                     </tr>";

        while($row = mysql_fetch_array($result))
        { 
            echo    "<tr>
                        <td><input type='checkbox'></input></td>
                        <td class='coursename'>" . $row['Course Name'] . "</td>
                        <td class='startdate'>" . $row['Start Date'] . "</td>
                        <td class='booktitle'>" . $row['Book Title']. "</td>
                        <td class='author'>" . $row['Book Author']. "</td>
                        <td class='isbn'><input class='ISBN_number' type='text' value='' size='13' maxlength='13'></input></td> 
                  </tr>";                   
        }               
echo "</table>";

mysql_close($con);

I’m trying to make it that when I click on the header (of the table) Course Name it will sort the Course Name column (and yes there is a space in it… the backticks take care of it.) It doesn’t work. On the other hand, when I tried putting in a simple html into my normal html code

<a href="#" class="Course_Name" value="Course Name Sort">Course Name Sort</a>

it now worked as I expected. Am I missing a concept or am I just making a simple error?

  • 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-05-26T16:20:44+00:00Added an answer on May 26, 2026 at 4:20 pm

    The problem is in the way you are assigning your click handler:

    $("#build_table,.Course_Name,.Start_Date,.Book_Title,.Book_Author,.Book_Isbn")
    .click(function() { 
        // your handler code
    });
    

    What this says is “assign a click handler to any elements that currently match the supplied selector”. This handler does not apply to elements that you later create dynamically (or load via Ajax).

    Fortunately jQuery does allow you to assign a handler in other ways such that it will apply to elements created in the future: you can use .live() or .delegate() to setup your handler, or if you’re using jQuery 1.7 these have been deprecated in favour of .on().

    I haven’t actually used .on() yet, but here’s how you could use .delegate():

    $(document).delegate(
       "#build_table,.Course_Name,.Start_Date,.Book_Title,.Book_Author,.Book_Isbn",
       "click",
       function() { 
           // your handler code
    });
    

    I suggest you read the doco for all three methods.

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

Sidebar

Related Questions

Would like to be able to set colors of headings and such, different font
I would like to clarify what is the proper way to filter user input
Im doing a ruby on rails project for work and they would like to
Before you start reading I would like to clarify: I have already thought of
I have some questions regarding MVC that I would like to clarify. At our
Threads such as PHP Session Fixation / Hijacking and some people like Chris Shiflett
I would like to clarify the if and unless statements in ANT script I
As a new comer to WPF, I would like to clarify my approach to
First, I would like to clarify a quick question I have, am I right
I would like to intercept any URL which the user enters in their browser

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.