1

I have a table, in a grid of 4x4. Assume they're all black boxes. I now have it so that when I hover, they turn grey.

However, how would I make it so that if you click on a table cell, it stays grey, and I can somehow pass that cell's coordinates to a $_POST function? I hope I am being descriptive enough.

4 Answers 4

4

$_POST is generally used for form data, so you would need to populate (via javascript) a hidden <input> element on click with the data you want passed. Depending on how you want to trigger the $_POST you could submit the form in the same click event, or by some other action.

The point is the only way to pass data through $_POST is normally through a form or through AJAX.

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

Comments

0

Make your table such that each cell has an onclick event defined. Call a function to submit the form through post when this function is called.

2 Comments

I'm trying to make this work, but I'm outputting the table using a PHP loop. This seems to make onclick events not work.
The browser, which runs the JavaScript (like the onclick events) doesn't know your page was generated by PHP. The problem is your code generating the wrong output, not that you used a loop or any other structure. It's an error in your logic, not in the tools.
0

jQuery fanboy here -

 $('td').click(function() {
        $.post("table_process.php", { cell: $(this).attr("#cell_id") },
             function(data){
                 alert("Cell: " + data);
             });
    });

Should be something like that.

http://api.jquery.com/jQuery.post/

3 Comments

how do you know the OP is using jQuery?
I assumed that he could resort to using jQuery. =/. Your answer is better, though. Makes more sense.
I tried doing that but it didn't work one way or another. It seems no matter what kind of JS or how much I put in, it has no actual effect on any behavior of the webpage in any way.
0

Library agnostic way of doing it: http://jsfiddle.net/sdleihssirhc/eBD9L/

It uses td:hover, so it won't work on IE6 and whatnot.

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.