Forum Moderators: open
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]
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.
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 + "&old=" + order[0] + "&new=" + order[1];
}
<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. :)