I have a list box and a button next to the list box. I’m trying to make the page change on the list box item that’s selected. So, an item is selected then the button is pressed, which changes the page and passes the item into a search page.
At the moment, as I press a button in the List Box, it changes the page. It doesn’t wait for you to press the button. The HTML provided is here
<div style="margin:auto">
<h3 style="text-align:center">
Or Search By Home Town:
<select id="myTown">
<?php
include("scripts/dbconnect.php");
include("scripts/lists.php");
?>
</select>
<input type="button" value="Search" />
</h3>
The selector I have is here :
$('#myTown option').click(getTown);
function getTown(){
var town=$(this).val();
window.location='searchresults.php?querystring='+town+'&querydesc=Town= &querytype=4';}
I think “this” should change to button or something along those lines.
or the selector “option” needs to be changed. if anyone can help that’d be great. Thanks.
Why don’t you just assign an event handler for the button:
and then get rid of the event handler for the option tag
update (if you can’t change html):