Click to See Complete Forum and Search --> : open a page using javascript using combobox


rosy
11-24-2006, 03:30 PM
Hi,
how to open a page using javascript by selecting an item in combobox.
If i choose an item in combo box

if (form.element.selectedIndex =="1"){
window.open("example.htm");
}

Thanks and any help would be appreciated.

sneakyimp
11-25-2006, 05:04 PM
You should be able to make this do what you want with a little modification.

<script language="Javascript">
function my_function(argSelect) {
alert('selected:' + argSelect.options[argSelect.selectedIndex].value);
}
</script>
<select onChange="my_function(this)">
<option value="page1.htm">First Choice</option>
<option value="page2.htm">Second Choice</option>
<option value="page3.htm">Third Choice</option>
</select>

rosy
11-27-2006, 11:12 AM
Thanks a lot its working, but if i choose only yes, it should redirect to page1.htm.(Its working) but if i choose again No, it should remain in same page.
The page url is /currentpage.php?update=value
How i can do this.?.

<select onChange="my_function(this)">
<option value="" SELECTED>No</option>
<option value="page1.htm">Yes</option>
</select>

Thanks.

sneakyimp
11-27-2006, 11:27 AM
check to see if the value = ""
if it does, then do nothing.

rosy
11-27-2006, 11:34 AM
Hi,
I checked with value = ""

<select onChange="my_function(this)">
<option value="" SELECTED>No</option>
<option value="page1.htm">Yes</option>
</select>

Its opening a page
about:blank in url.
I want to remain in the same page instead of opening a blank page.
How can i do it. Any help will be appreciated.
Thanks.

rosy
11-27-2006, 02:08 PM
Hi,
I found out how to make it.It works,
I used

location.href(argSelect.options[argSelect.selectedIndex].value);

Thanks.