0

Hi – I have an inline jQuery function that selects the table cell data onclick. The jQuery part works well. I have added code snippet of jquery.

$(function(){   $("#myTable td").click(function() {
$row = $this.closest('tr');
case "name":        
            alert($row.find(".name").html());   
            break;  
etc

Instead of displaying the name on the client –side alert message, I am trying to pass the clicked table column to php when the user clicks the button on HTML document. I am new to php and it could be easier to fix. I have searched a lot and no luck. Please help me.

Thanks in advance.

Edited by Ezzaral: Code format.

4
Contributors
9
Replies
17
Views
5 Years
Discussion Span
Last Post by blocblue
0

Depending on what you're trying to accomplish with the value you pass to PHP, you could try using the jQuery Post function.

$(function() {
    $('#myTable td').click(function(event) {
        var value = $(this).closest('tr').find('.name').html();

        $.post('test.php', {value: value}, function(response) {
            alert(response);
        });
    );
});


<?php // test.php
    $value = isset($_POST['value']) ? $_POST['value'] : null;
    die("Posted: {$value}");

R.

Edited by blocblue

0

Hi blocblue , Thanks for your code. This works well and posts back the column data to php without any problem.

I have a button on the html form when it is clicked the column td data needs to be post back to php and it should be displayed on that window.

For me, the jQuery alert button with data is displayed on the same window very well. But not on the test.php. All I want is just display the clicked td data on next window (test.php) when the button is clicked on the first window.

This is the code I have currently:

<form id=form1 action="test.php" method="POST"  >
    <table id=myTable border=1>
        <tr>
...
<input type='submit' value='Save' onclick=" " />


<?php // test.php  
  $value = isset($_POST['value']) ? $_POST['value'] : null;  
  die("Posted: {$value}");

Edited by madhan

0

Hi - Can anyone please help me on this issue? I am having hard time fixing this....
Thanks

0

test.php is run silently, anything it outputs will be in the response. Just show the response where you need it using Javascript. If you need it in the next page, just insert a hidden input tag with the value into your DOM (assuming this is what you mean, if not, please explain your flow).

0

Hi, Thanks for your reply. I have doubt that posting back HTML table clicked column is possible in javascript. if posible could you please show me some code sample?

Here is the flow/goal:

  1. html table column gets clicked using jquery.

  2. user clicks the button (form action =POST)

3.show the clicked column in other page (eg, test.php page)

step 1 works well. Having trouble sending the table clicked column to post back on next window. please help.

Right now, Button gets clicked and test.php gets run but the clicked table column value is not dsplayed on the other window. Tha clicked column value gets displayed on the same page perfectly as blocblue suggested.

Edited by madhan

0

Have a look at this SO thread. I think that is what you want to happen when you click a column. The logic may need to change somewhat though, but have a go with this first.

0

Sorry for the slow reply. For some reason, I've stopped receiving emails from DaniWeb following someones reply to threads I've responsed to.

Anyhow, I think the title of your thread was a little misleading as to what it was you're trying to achieve. If you simple want to pass the name of the clicked column through to the post action page, then a hidden input field would most likely suffice.

For example:

$(function() {
    $('#myTable td').click(function(event) {
        var value = $(this).closest('tr').find('.name').html();
        $('#column').val(value);
    );
});


<form id=form1 action="test.php" method="POST"  >
    <table id=myTable border=1>
        <tr>
        ...

    <input id="column" type="hidden" name="column" value="" />
    <input type="submit" value="Save" />
</form>

Then upon submitting your form to test.php, you can access the column value as follows:

// Be sure to validate the input before use
$column = isset($_POST['column']) ? $_POST['column'] : null;

Best,
R.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.