Reputation: 3081
I have the following jquery code:
$(document).ready(function()
{
$("#build_table, a.coursename, .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>");
});
}
});
});
At the way beginning, I have a click function which I want to work for multiple butttons. This code will call a php file to build a table, and the resulting table headers have different class names (such as coursename). But it doesn't actually work for coursename, Start date, etc, only for build_table which was the button that built the table in the first place. Am I missing something? I know that the names are correct, I even tried to take the space out of one of them (a.coursename) and that still didn't work...
Upvotes: 0
Views: 103
Reputation: 1174
I have implement this and its work..
HTML code:
<input type="button" value="Build table" id="build_table"/>
<input type="button" value="Course name" class="CourseName"/>
<input type="button" value="Start date" class="StartDate"/>
<input type="button" value="Book title" class="BookTitle"/>
<input type="button" value="Book author" class="BookAuthor"/>
<input type="button" value="Book isbn" class="BookIsbn"/>
jquery code:
$(document).ready(function(){
$("#build_table, .CourseName, .StartDate, .BookTitle, .BookAuthor, .BookIsbn").click(function(){
alert("Yehh!! Its wroked :)");
//your further code
});
});
Upvotes: 1