How to print php dropdown in loop using javascript
Hi i am trying to print the text-box and the drop-down from database.
I am printing the text-box and drop-down based on input given.
for ex:say i am giving input as 4
for that it will create 4 text-boxes and drop-downs.
but i have the dropdown code in php..so now i want to print the php
dropdown in loop using javascript..How can i do This?
javascript code:
function create(param) {
'use strict';
var i, target = document.getElementById('screens');
target.innerHTML = '';
for(i = 0; i < param; i += 1) {
target.innerHTML +='</br>';
target.innerHTML +='New Movie '+i+' ';
target.innerHTML += '<input type="text" name="Fname">';
target.innerHTML +=' '+'Language '+' ';
target.innerHTML += '<input type="text" name="timings">';
target.innerHTML +='</br>';
target.innerHTML +='</br>';
}
}
php dropdown:
<?php
try {
$dbh = new
PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SELECT language FROM languages;";
$sth = $dbh->prepare($sql);
$sth->execute();
echo "<select name='language' id='course'>";
echo "<option>----Select Language----</option>";
while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='" . $row['language'] ."'>" .
$row['language']. "</option>";
}
echo "</select>";
?>
in place of
target.innerHTML += '<input type="text" name="timings">';
i should get php dropdown instead of textbox.
No comments:
Post a Comment