140
rated 0 times
[
145]
[
5]
/ answers: 1 / hits: 26518
/ 10 Years ago, wed, april 23, 2014, 12:00:00
I have a problem with my code.
case like this:
I have a dropdown, if selected personal it appeared the new dropdown that contains the data that is retrieved from a database query, if selected public, then the dropdown disappear.
HTML code like this:
<select name=use class=dropdown id=sender onChange='changeSend()'>
<option value=1>Public</option>
<option value=0>Personal</option>
</select>
<div id='send2'></div>
Query like this:
<?php
$query = mysql_query(select * from data where id_user = '$id_user' order by date asc);
$i = 0;
$id = array();
$name = array();
while($data = mysql_fetch_array($query)){
//id from result database query
$id[$i] = $data['id'];
//name from result database query
$name[$i] = $data['name'];
$i++;
}
?>
JavaScript code like this:
function changeSend() {
var selectBox = document.getElementById(sender);
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
if (selectedValue==0) {
$('#send2').html(<select class='dropdown'><option value='-id from result database-'>-name from result database query-</option></select>);
} else {
$('#send2').html('');
}
}
I dont know how to send value/result ($id[0],$name[0],$id[1],$name[1], etc..)
to javascript code(value and name in select options).
More From » php