-1

As i mention on the question, i want to update one select box if another value in the another select box is selected.

for example:

<select id="makale" size="4"name="formMakale"style="height:7em;width:16em;border:0px;outline:0px;font-size:16px;padding-left:10px;" >
<?php 
    $authorsQuery = $hb->authors();
    foreach($authorsQuery as $v){
        echo '<option value="'.$v->id.'">'.$v->name.'-'.count($hb>aticlesbyauthor($v),1000).' yazi</option>';}
?>
</select>

<select id="kategoriSec"  size="4" name="formCat"style="height:7em;width:16em;border:0px;outline:0px;fontsize:16px;padding-left:10px;" >
<?php 
$catQuery = $hb->db->get_results("SELECT * FROM category");
    foreach ($catQuery as $v) {
        echo '<option value="'.$v->id.'">'.$v->name.'</option>';
    }
?>

if i select something from this select box with id makale, i want to update the options of the select box with id kategorisec.

can you help me?

Thank you.

  • 1
    Possible duplicate of [Populating One Select Box Based on the Selection in Another Select Box - JQuery?](http://stackoverflow.com/questions/5861090/populating-one-select-box-based-on-the-selection-in-another-select-box-jquery) – Stu Aug 07 '16 at 17:14
  • @Stu Could be a possible duplicate. However that accepted answer only contains links and I have left a comment under it about it. It would be best if you were to choose a better (possible) duplicate ;-) – Funk Forty Niner Aug 07 '16 at 17:18
  • @Fred-ii- yes, very true! This is asked a lot, so some food for thought for OP: [List of possible answers](https://www.google.es/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:stackoverflow.com+updating+a+select+box+based+on+another) – Stu Aug 07 '16 at 17:24
  • @Stu I know. There is ample information out there for them to look up and use/try. The question shows no effort whatsoever. If they did try something and failed, then it (Mustafa) should have been included in it. – Funk Forty Niner Aug 07 '16 at 17:30
  • 1
    @Fred-ii- again 100% with you :) I am a firm believer in pointing people in the right direction so that they can work out the answer themselves, I think that's better for self development rather than being given a coded answer in most cases... and I'm appreciative when people do the same when I ask questions :) An example of "what I've tried" shows some effort in getting there... – Stu Aug 07 '16 at 17:33

1 Answers1

0

If you just want to change it on the browsers side, use the onchange event handler.

If you want to update the checkboxes based on server data, you could use ajax or simply use an iframe:

<input onclick="update(this)">
<iframe src="checkboxes.php">Oh ,update your browser</iframe>
<script>
function update(elem){
if(elem.selected){ iframe=document.getElementsByTagName("iframe")[0]
iframe.src="checkboxes.php?select="+elem.value;
}
}
</script>
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151