Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript not working in Firefox (onchange + location.href)

Status
Not open for further replies.

gia999

Programmer
Mar 26, 2008
14
GB
Hello there,

I am using an onchange event to trigger my javascript code, this code them refreshes the page to change form field options depending upon what the value of another selected field is. This works fine in IE but just wont work at all in Firefox :(. I have done some testing and things tried so far don't seem to help. If anyone could let me know how I get this to work on all browsers that would be so so great... My code is :

Javascript code :

function boxChange()
{
url = "timesheets.asp?add=yes&cid=" + timesheetForm.companyID.value + "&mid=" + timesheetForm.managerID.value + "&we=" + timesheetForm.tWE.value;
location.href=url;
}


Event trigger on the form :

<select name="companyID" id="companyID" onChange="boxChange()">

Any help would be so much appreciated.

Thank you
Gia
 
Try using a fully qualified URL for the location.href assignment. Something with http:// in the front.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hi Jeff,

Thank you for repying, I have tried what you have suggested and sadly it still doesn't work at all in Firefox :(

Do you know anything else I can try?

Many thanks,
Gia
 
You need to define "timesheetForm". IE lets you get lazy... Firefox does not.

Use any of the following, or use something different - there are many ways to skin this cat:

Code:
var timesheetForm = document.forms['timesheetForm'].elements;

var timesheetForm = document.getElementById('timesheetForm').elements;

var timesheetForm = document.getElementsByTagName('timesheetForm')[0].elements;

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Against all oddities, you can do this.
[tt]
function boxChange()
{
//all references to form and fields are by name and presumed non-multiplicity,
//otherwise, adjust accordingly
[blue]var[/blue] url = "timesheets.asp?add=yes&cid=" +
encodeURIComponent(document.timesheetForm.companyID.value) + "&mid=" +
encodeURIComponent(document.timesheetForm.managerID.value) + "&we=" +
encodeURIComponent(document.timesheetForm.tWE.value);
location.href=url;
}
[/tt]
 
Hello,

Thank you so much for your help everyone. I actually used your suggestion Dan and it now works perfectly in Firefox which is fantastic!!

Thank you again, Gia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top