0

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...

3
  • 3
    Really need to see the HTML to give a full answer, but with the information provided I will say that CSS classes cannot have spaces in them, otherwise how could a CSS parser tell the difference between a combinator and white space in a class name? Commented Nov 7, 2011 at 19:52
  • Agreed. You've asked 14 questions and accepted 3. This is a community, and you have a part to play too. Commented Nov 7, 2011 at 22:17
  • Accepting/Upvoting the answer is the best way of appreciating. Commented Nov 8, 2011 at 9:25

1 Answer 1

1

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

    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.