I have this file that contains a javascript variable:


    <select name="creditmemo[reason]">
        <option value="wrong">Fraudulent</option>
        <option value="not_available">Unavailable</option>
        <option value="request">Request</option>

    <script type="text/javascript">

            var cancelAndRefundSelectElement = document.getElementsByName("creditmemo[reason]")[0];



Now, I need to send that variable to this PHP file:


public function reason(){


The problem is that I don't know how to call it from there and return it.

The code is longer, but I just wrote that the necessary things for the sake of the example.

Basically, how can I send the value of the variable from the 1st file (phtml) to the 2nd file (php)?

Thank you!

  • You can not send Javascript variable to PHP variable because Javascript is client-side and PHP is server side. You can use a cookie for handling values of your variable because the cookie is supported client side as well as server side both. – Pragnadeep Pitroda Jun 2 at 14:07
  • why not use wrap your select option in a form and pass its value to the other php file using post method ? – fmsthird Jun 3 at 2:31
  • I'm new to PHP, can you give me an example on how to do it? Thanks! – dragon25 Jun 3 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.