0

I will send a variable to the php but I did not find the way I expected. Can you guys help me. I want to send a value that is in the select box into a php variable. here's my code :

<select name="month" class="form-control">
    <option value="">-Choose Month-</option>
    <option value="0">January</option>
    <option value="1">February</option>
    <option value="2">March</option>
    <option value="3">April</option>
    <option value="4">May</option>
    <option value="5">June</option>
    <option value="6">July</option>
    <option value="7">August</option>
    <option value="8">September</option>
    <option value="9">October</option>
    <option value="10">November</option>
    <option value="11">December</option>
</select>
<script type="text/javascript">
    $(document).ready(function(){
        $("[name=month]").change(function(){
            var month = $(this).val();
            var t = "<?php $t="+month+" ?>";
        });
    });
</script>
<?php
$t = "";
echo "Month = ".$t;
?>
  • 1
    Somehow, I feel you need to start with the basics of Client/Server architecture. – Sunny R Gupta Dec 14 '14 at 05:31
  • You cant do it like this. Once a page is loaded means server side script is executed. Then you cannot echo – Indra Kumar S Dec 14 '14 at 05:31
  • You need to use js only – Indra Kumar S Dec 14 '14 at 05:32
  • you said.`var t = "";` you can't do that, not even close. All the PHP code runs. Then the page is sent to the browser. And then all the javascript runs. To send a value from javascript back to the server is possible but won't arrive in he context of the HTML generation.For sending values back to the server you want something like ajax. – Jasen Dec 14 '14 at 05:55

0 Answers0