1

I have this php code that get items from the database and i have to use this drop-down in my JavaScript code to duplicate the same drop-down when a button is clicked

function dup(){  
     }

 <?php 
  include('view/connect.php');

  $sql="SELECT ss_code FROM ss WHERE sn_id = 1";

  $result =mysql_query($sql);
  $dropdown = "<select name='users'>";

  while($row = mysql_fetch_assoc($result)) {
     $b = $row['ss_code'];
     $dropdown .= "\r\n<option value='{$b}'>{$b}</option>";

  }

  $dropdown .= "\r\n</select>";

  echo $dropdown;

 ?>

2 Answers 2

1

Put all your items in an array and then set a JavaScript variable to the value returned by encoding it as JSON.

var iarray = <?php echo json_encode($items); ?>;

Then iterate over the resultant array and create the pulldown from that.

Sign up to request clarification or add additional context in comments.

Comments

0

What do you mean same drop down?If you want same dropdown without any change on a button click you can use jQuery .clone().

Comments

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.