javascript - how to select the select box item based on another and vice versa -
how select select box item based on 1 , vice versa.here use ajax redirect query page.
while($fet = mysql_fetch_assoc($sql1)) { echo "<option value=".$fet['username'].">".$fet['username']."</option>"; } echo '</select></td>'; echo "<td><div id='mydiv'><select id=id name=id onchange=loadxmldoc()>"; $sql = "select * sample"; $sql1 = mysql_query($sql); while($fet = mysql_fetch_assoc($sql1)) { echo "<option value=".$fet['id'].">".$fet['id']."</option>"; } echo '</select></div></td>';
you need use ajax that, example have select this
<select id=id1 name=id1 onchange=loadxmldoc()>
here second 1 want change <select id=id2 name=id2>
on javascript call php file via ajax this
function loadxmldoc(){ $.ajax({ // think used jquery on project type: "post", url: "getdata.php", data: $('input[\'name=id1\']'), datatype: "json", success:(function(result){ html = ''; if(result.data.length > 0){ $.each(result.data, function( index, value ) { // alert( index + ": " + value ); html += '<option value="'+value.id+'">'+value.title+'</option>'; }); $('#id2').html(html); }else{ // nothing } })); }); }
then on php file echo json_encode result want get
$sql = mysql_query('select id,title your_table your_field='.$_post['id1']); $query= mysql_query($sql); while( $row = mysql_fetch_array($query)){ $json['data'][] = array('id' =>$row->id,'title'=>$row->title ) } echo json_encode($json);
Comments
Post a Comment