0

I have php variable called itemId in same phtml file and i got td value using js. now i need to assign that var id value to $itemId variable.

<?php

$itemId = null;

?>



        <table class="item-table">
        
            <tr data-row="product-item" id="<?= $block->escapeHtmlAttr($item->getId()) ?>" onclick="getTableRowData(this)">
              
                <td class="item-id" id="item-id">
                    <span class="item-id-span">
                        <?php echo $item->getId(); ?>
                    </span>
                </td
            </tr>
    </table>


<script>

function getTableRowData(row) {
var cells = row.getElementsByTagName('td');
        var id = cells[1].innerHTML;
}

</script>

1 Answer 1

0

Unless I'm misunderstanding your question what you're asking for isn't possible. PHP is executed server-side, meaning there's no interacting with PHP through static, client-side JavaScript.

You could, however, do the inverse and use PHP to render values into your JavaScript and then interact with that data as needed on the client-side.

Alternatively you could use client-side ajax to request data from a PHP script server-side.

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.