Diego Diego - 2 months ago 6
Javascript Question

How to give action to selected combo box

Hi, i want to use search by id and search by date

<select id="menu">
<option value="<?=site_url('web/execute_search')?>">By Id</a></option>
<option value="<?=site_url('web/execute_searchs')?>">By Date</a></option>
</select>
<input type="text" name="search" />
<input type="submit" value="Submit" />


I have combo box, when i select search by id and submit so it will go to Controller ('web/execute_search') , then if i select date and submit, go to Controller ('web/execute_search').

Answer

Try this code:

<select id="menu" onchange="option()">
    <option value="1" content="1">By Id</a></option>
    <option value="2" content="2">By Date</a></option>
    </select>

    <input type="text" name="search" />
    <input type="submit" value="Submit" />

then here's javascript:

<script>function option(){
var x = document.getElementById("menu").value;
if (x==1){
    window.location.href = "execute_search";
}
if (x==2){
window.location.href = "execute_searchs";
}}</script>