Forum Moderators: open

Message Too Old, No Replies

Javascript not working in FireFox

which is working fine in IE

         

Murali

9:55 am on Feb 23, 2005 (gmt 0)

10+ Year Member



Hi

in my webpage, I am using a inputbox to accept email id (NOT inside a form).
<INPUT class=inputbox id=Text3 name=newsemail>

But when i access that element using javascript, it is giving the following error

Error : newsemail is not defined.

It is working fine in IE. What is wrong with FireFox?


function newsletter()
{

if(newsemail.value.indexOf("@")==-1 ¦¦ newsemail.value.indexOf(".")==-1)
{
alert("Invalid email address");
newsemail.focus();
return;
}
location.href="http://www.example.com/newsletter.asp?email="+newsemail.value;
}

[edited by: BlobFisk at 9:43 am (utc) on Mar. 9, 2005]
[edit reason] Use example.com [/edit]

dcrombie

10:14 am on Feb 23, 2005 (gmt 0)



Error : newsemail is not defined.

Browsers other than IE don't create global variables for every part of the page/DOM. You will need to properly reference the form element either by passing it (or the form) as a reference, or using absolute reference through the document.forms collection.

Afkamm

12:57 am on Mar 9, 2005 (gmt 0)

10+ Year Member



Aha :)

I've been having a similar problem. Works fine in IE and Opera, but not in Firefox. Doesn't work at all on a Mac so I'm told.

This is the function I'm currently using...

function order(url, number) {
var separator = '¦';
var order = number.split(separator);
document.location.href = url + "&amp;old=" + order[0] + "&amp;new=" + order[1];
}

...and this is the html that calls it...

<select name="order" onChange="order('admin.php?mode=order', 'this.options[selectedIndex].value');">

Firefox will go so far as to send you to the next page when an option from the drop down men has been selected, but it wont pass the values.

This is inside a form already, but must be kept separate which is why I use javascript. Is there any other way around this Firefox issue?

Thanks. :)

Afkamm

2:50 am on Mar 18, 2005 (gmt 0)

10+ Year Member



I found a solution. Changing the &amp;'s to &'s did the trick. :)