0

i have from drop down onchange redirect, when i select one of value, page when i redirect not changet value from drop down onchange redirct. my javascript

<script language="JavaScript" type="text/javascript">
                    function redirect(site){
                        window.location= site
                    }
                </script>

on my form like this

<select name="bulan" onchange="redirect(this.value)">
                    <option value="#">Pilih Bulan</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/01">Januari</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/02">Februari</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/03">Maret</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/04">April</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/05">Mei</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/06">Juni</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/07">Juli</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/08">Agustus</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/09">September</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/10">Oktober</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/11">November</option>
                    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/12">Desember</option>
                </select>

how i get the value selected from this form ??

Suzt
  • 33
  • 2
  • 10
  • I think you are using one of MVC framework. Probably, something wrong in your URL pattern. Inspect them ( – Sithu Jan 24 '13 at 04:53
  • http://localhost/portal/index.php/kalender/cari_agenda/1/01, i want to get the "1" from url pattern – Suzt Jan 24 '13 at 04:57
  • "1" is category, "01" is month – Suzt Jan 24 '13 at 04:58
  • what you want to do actually? Your code is correct. It should redirect as expected. – Sithu Jan 24 '13 at 05:00
  • when i select from drop down onchange, example "Januari", the redirect page also display "Januari" from drop down onchange not "pilih bulan" – Suzt Jan 24 '13 at 05:03

2 Answers2

1

According to the comments with me, you are trying to select the current option upon the last argument in the URL. You just need selected="selected". Try this:

<select name="bulan" onchange="redirect(this.value)">
    <option value="#">Pilih Bulan</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/01" <?php if($this->uri->segment(4) == '01') echo 'selected="selected"'; ?>>Januari</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/02" <?php if($this->uri->segment(4) == '02') echo 'selected="selected"'; ?>>Februari</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/03" <?php if($this->uri->segment(4) == '03') echo 'selected="selected"'; ?>>Maret</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/04" <?php if($this->uri->segment(4) == '04') echo 'selected="selected"'; ?>>April</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/05" <?php if($this->uri->segment(4) == '05') echo 'selected="selected"'; ?>>Mei</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/06" <?php if($this->uri->segment(4) == '06') echo 'selected="selected"'; ?>>Juni</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/07" <?php if($this->uri->segment(4) == '07') echo 'selected="selected"'; ?>>Juli</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/08" <?php if($this->uri->segment(4) == '08') echo 'selected="selected"'; ?>>Agustus</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/09" <?php if($this->uri->segment(4) == '09') echo 'selected="selected"'; ?>>September</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/10" <?php if($this->uri->segment(4) == '10') echo 'selected="selected"'; ?>>Oktober</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/11" <?php if($this->uri->segment(4) == '11') echo 'selected="selected"'; ?>>November</option>
    <option value="<?= base_url(); ?>index.php/kalender/cari_agenda/<?= $this->uri->segment(3); ?>/12" <?php if($this->uri->segment(4) == '12') echo 'selected="selected"'; ?>>Desember</option>
</select>
Sithu
  • 4,752
  • 9
  • 64
  • 110
0

The script that you written works just fine. I can assume that it is something wrong with URL or other js code on the page. If you are using URL without protocol (e.g. http://) then it may cause the problem for redirection.

If you want get a category, as you pointed it in your comment. Then I suggest this:

<script type="text/javascript">
function redirect(site){
    var category = site.split('/')[5];
    //other code goes here...
}
</script>
Soul_man
  • 575
  • 5
  • 15