I have a small form on my page where a user can either search for availability at a specific hotel, or search for availability at all hotels:
<script type="text/javascript" language="javascript">
function Redirect() {
if (searchAll) {
document.getElementById("Hotel").value = "0";
}
return true;
}
</script>
<form name="form1" action="search.asp" method="POST" id="form1"
onsubmit="return Redirect()">
<input type="hidden" id="Hotel" name="Hotel" value="<%= HotelID %>">
<input id="btnHotelSearch" type="submit" name="btnHotelSearch"
value="Search This Hotel" onclick="searchAll=false">
<input id="btnHotelSearchAll" type="submit" name="btnHotelSearchAll"
value="Search All Hotels" onclick="searchAll=true">
</form>
Whenever a button is pushed, I run some javascript to set the HotelID being passed. This works fine in Firefox. But in IE, whenever I push either button, I get a script error saying ‘searchAll’ is undefined
What do I need to do to fix that?
You need to declare the
searchAllvariable outside of theRedirectfunction, so it’s in the global scope and therefore accessible from theRedirectfunction, and your inline event handlers: