0

url : http://localhost/back-office/index.php/staff/shopping

when i change the category on every onchange event i want the url should be like this

http://localhost/back-office/index.php/staff/shopping/1
http://localhost/back-office/index.php/staff/shopping/2

for that i wrote javascript on change event

function cat()
{
    var x = document.getElementById('cat').value;   
    document.location = "shopping/" + x;


}


     <select name="cate" id="cat" onchange="cat()">
        <option value="0">Select Cateogry</option>
        <?php 
        foreach($get_cat as $category)
        {
            echo "<option value=$category->categoryid>$category->category</option>";            
        }
        ?>    
    </select> 

the javscript works , but the url getting appended like

http://localhost/back-office/index.php/staff/shopping/shopping/2

http://localhost/back-office/index.php/staff/shopping/shopping/shopping/shopping/shopping/shopping/1

on every cagetory drop box onchange event the url is getting appended like this at the end.

how could i solve this

Ragavendran Ramesh
  • 376
  • 1
  • 7
  • 23

1 Answers1

1

you need to specifically code your url..try this

function cat()
{
    var x = document.getElementById('cat').value;   
    url  = "http://localhost/back-office/index.php/staff/shopping/" + x;
    window.location = url;

}
ruelluna
  • 787
  • 1
  • 11
  • 30