Forum Moderators: open
The script works fine in IE but, to my surprise doesn't respond in Opera.
The URL is generated when the user clicks an input button but nothing happens in Opera. The script is as follows:
----------------------------------
function go(){
var L1 = document.theform.list1.value;
var L2 = document.theform.list2.value;
if (L1!= "#" && L2!= "#")
{
var url = "http://www.example.com/events/" + L1 + L2 + ".htm";
location.href(url);
}
}
--------------------------------------
and the form it is functioning on looks like this:
--------------------------------------
<form name="theform">
<select name="list1" size="1" style="background-color:#ffffff; color: #666666; width: 160px;">
<option value="#" SELECTED>-- Select Month --</option>
<option value="jan">January</option>
<option value="feb">February</option>
<option value="mar">March</option>
<option value="apr">April</option>
<option value="may">May</option>
<option value="jun">June</option>
<option value="jul">July</option>
<option value="aug">August</option>
<option value="sep">September</option>
<option value="oct">October</option>
<option value="nov">November</option>
<option value="dec">December</option>
</select>
<select name="list2" size="1" style="background-color:#ffffff; color: #666666; width: 160px;">
<option value="#" SELECTED>-- Select Event Type --</option>
<option value="ae">All Events</option>
<option value="de">Day Events</option>
<option value="wb">Weekends Breaks</option>
<option value="pt">Personalised Tours</option>
</select>
<input type="button" value="Go" onclick="go()"/>
</form>
---------------------------
Would anyone be able to offer any solutions as to why it does not work in Opera and come up with a fix?
(Note: the script has not been tested in Netscape so I don't know if it works in Netscape)
Many Thanks
CK
[edited by: tedster at 10:02 pm (utc) on Mar. 13, 2003]
[edit reason] make the url generic [/edit]
function go(){
var L1 = document.theform.list1.options(list1.selectedIndex).value;
var L2 = document.theform.list2.options(list2.selectedIndex).value;
if (L1!= "#" && L2!= "#")
{
var url = "http://www.birdwatchnorthumbria.co.uk/events/" + L1 + L2 + ".htm";
location.href(url);
}
}
IE - forgiving as it is - let you use syntax that, strictly speaking, is incorrect. For instance, if the select box allowed multiple select, it wouldn't have done what you intended.
First I would change the function name away from go. It may be causing problems. Have you tried assigning the object instead of calling the method?
location.href= url;
I also thought that only jscript supported non array calls to selected indexes. This could also be an issue. I think you should use [] instead of () for the array to.
var L1 = document.theform.list1.options[theform.list1.selectedindex].value;
var L2 = document.theform.list2.options[theform.list2.selectedindex].value;
I don't think you need an action defined with Opera in the form tag.