MIRMIX
MIRMIX

Reputation: 1080

To parse the value of dropdown list in JS to php

Hi I created the dropdown list below. I should get the value and parse it to php.

<script>
    document.write('<form method="post">');
    document.write('<select name="myOption" id="mySelect">');
    for(var i=0;i<<?php echo json_encode($clusterids); ?>.length;i++)
      document.write('<option>clusterid: '+<?php echo json_encode($clusterids); ?>[i] + '</option>');
    document.write('</select>');
    document.write('</form>');
</script>

I tried this code in php but it does not work

  <?php 
         $option = $_POST['myOption'];
         echo $option;
 ?>

Upvotes: 1

Views: 244

Answers (1)

Ion Bazan
Ion Bazan

Reputation: 838

As turson suggested, you need to add a submit button or input to submit your choice. Add this just before your form closing tag:

<input type="submit"/>

Upvotes: 2

Related Questions