homepage Welcome to WebmasterWorld Guest from 54.167.11.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript intergrated with select menus
Script needs fixing for Opera
psychomonkeyCK




msg:1486135
 6:19 pm on Mar 13, 2003 (gmt 0)

I have a script to produce a URL from two variables; month and event type.

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]

 

ricfink




msg:1486136
 8:14 pm on Mar 13, 2003 (gmt 0)

Tested a variation of this in Opera and it worked fine.

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.

psychomonkeyCK




msg:1486137
 9:47 pm on Mar 13, 2003 (gmt 0)

Hmm I updated the Jscript with that and tested it again and it still doesnt seem to work.

It may be a problem with the button or the fact that the form has no action specified?

Thanks for trying, any more offers?

CK

psychomonkeyCK




msg:1486138
 10:11 am on Mar 15, 2003 (gmt 0)

Anyone?

psychomonkeyCK




msg:1486139
 8:36 pm on Mar 18, 2003 (gmt 0)

Somebody please help me out here!

CK

korkus2000




msg:1486140
 8:47 pm on Mar 18, 2003 (gmt 0)

hey psychomonkeyCK,

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved