473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

this code works in IE but not Firefox - please help

Both of the following code smippets work in IE but not in Firefox. The
javascript error for both scripts below is "x has not properties".

The select boxes are shown as arrays since they are generated by Pear's
Quickform - no way around it - I tried.

This code in the html calls the function above and should copy the value
selected in a pull-down list to another field:

<script type="text/javascript">
var x=document.getElementById('fld[2]');
</script>
<script type="text/javascript">function addOption(){

myList = document.getElementById('lfld');
document.forms[0].elements['lfld'].value =
document.forms[0].elements['lfld'].value + x.options[x.selectedIndex].text +
'\n';
}
</script>
<input onclick="addOption()" name="ibutTest" value="Click here to ADD
selected value" type="button" />

The following code should open a new window sending it a parameter to open:
'onClick' => "window.open('page1.php?i=' +
x.options[x.selectedIndex].value,'Name','toolbar=no, menubar=no,
scrollbars=yes, width=600, height=400, top=100, left=100')"
Many many thanks for your help!
Jan 10 '06 #1
5 2343
Notgiven said the following on 1/10/2006 5:06 PM:
Both of the following code smippets work in IE but not in Firefox. The
javascript error for both scripts below is "x has not properties".

The select boxes are shown as arrays since they are generated by Pear's
Quickform - no way around it - I tried.

This code in the html calls the function above and should copy the value
selected in a pull-down list to another field:

<script type="text/javascript">
var x=document.getElementById('fld[2]');
Why are you using gEBI to access a form element? Use the forms
collection. From what you indicate, fld[2] is the name of the select,
not its ID:

var x = document.forms['formNAMEnotID'].elements['elementNAMEnotID'];
</script>
<script type="text/javascript">function addOption(){

myList = document.getElementById('lfld');
document.forms[0].elements['lfld'].value =
document.forms[0].elements['lfld'].value + x.options[x.selectedIndex].text +
'\n';
}
</script>
<input onclick="addOption()" name="ibutTest" value="Click here to ADD
selected value" type="button" />

The following code should open a new window sending it a parameter to open:
'onClick' => "window.open('page1.php?i=' +
x.options[x.selectedIndex].value,'Name','toolbar=no, menubar=no,
scrollbars=yes, width=600, height=400, top=100, left=100')"


See above with regards to 'x'. Also, the third parameter to window.open
does not allow spaces, remove them.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 10 '06 #2
Notgiven wrote :
Both of the following code smippets work in IE but not in Firefox. The
javascript error for both scripts below is "x has not properties".

The select boxes are shown as arrays since they are generated by Pear's
Quickform - no way around it - I tried.

This code in the html calls the function above and should copy the value
selected in a pull-down list to another field:

<script type="text/javascript">
var x=document.getElementById('fld[2]');
Where is this script located in relation to the body node, in relation
to that fld[2] object/node? Before or after the select?
Providing an url showing the problem, allowing people reading your post
to test your webpage is always better.

MSIE 6 does NOT support the add method as described by DOM 2 HTML interface:
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-14493106
http://www.gtalbot.org/BrowserBugsSe...ptionNull.html

Firefox and Mozilla-based browsers do support the add method as
described by DOM 2 HTML.
</script>
<script type="text/javascript">function addOption(){

myList = document.getElementById('lfld');
document.forms[0].elements['lfld'].value =
document.forms[0].elements['lfld'].value + x.options[x.selectedIndex].text +
'\n';
}
</script>
<input onclick="addOption()" name="ibutTest" value="Click here to ADD
selected value" type="button" />
Is your webpage XHTML-based or HTML ?

The following code should open a new window sending it a parameter to open:
'onClick' => "window.open('page1.php?i=' +
x.options[x.selectedIndex].value,'Name','toolbar=no, menubar=no,
scrollbars=yes, width=600, height=400, top=100, left=100')"

The 3rd parameter of your window.open call is not written as best:
1- there should be no blank space between window features
http://developer.mozilla.org/en/docs...and_parameters
2- there is no need to list window features which are turn off
3- there is a necessary need to list the ones which are turn on:
resizable is not listed, therefore, you implicitly (or without knowing
it) want/demand the window to be non-resizable .. which is
anti-accessibility
4- the code makes the window for one usage only; it won't be reusable,
recyclable either because the script does not manage the returned object
reference. Again this is not recommendable.

DOM:window.open
http://developer.mozilla.org/en/docs/DOM:window.open

Gérard
--
remove blah to email me
Jan 10 '06 #3
"Notgiven" <no*********@invalid.invalid> writes:
Both of the following code smippets work in IE but not in Firefox. The
javascript error for both scripts below is "x has not properties". .... <script type="text/javascript">
var x=document.getElementById('fld[2]');
Even if there is an element with id="fld[2]", that is not a valid value
for the id attribute. My guess is that this is why Firefox won't find
it - it has already been "error corrected" away.

If it is a select element inside a form, then you can use:
var x = document.forms['idOfForm'].elements['fld[2]'];
to find it. If it is not inside a form, you can try using "fld[2]" as
the name property, not id, and use:
var x = document.getElementsByName('fld[2]')[0];

.... The following code should open a new window sending it a parameter to open:
'onClick' => "window.open('page1.php?i=' +
x.options[x.selectedIndex].value,'Name','toolbar=no, menubar=no,
scrollbars=yes, width=600, height=400, top=100, left=100')"


You should avoid spaces in the format string for window.open. Some
browsers consider it an error and fails.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jan 10 '06 #4
Notgiven escreveu:
Both of the following code smippets work in IE but not in Firefox. The
javascript error for both scripts below is "x has not properties".
var x=document.getElementById('fld[2]');


Please, don't tell me that you're doing something like this:

<input type="text" name="teletubbie" />

<script type="text/javascript>
alert(document.getElementById("teletubbie").name);
</script>

If you're doing this, do one of the following:

- use document.forms.YourForm["fld[2]"]...
- add the id property (name="teletubbie" id="teletubbie")
- or change the document.getElementById for document.getElementsByName

I preffer the first one ;]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 10 '06 #5
Fixed it guys - thanks very very much!

Here's what I changed:

var x = document.forms['formNAMEnotID'].elements['elementNAMEnotID'];

This worked immediately - well almost immediately when I figured out the
correct way to write.

I used the Web Developer 1.0 add-on to Firefox - it was immensely helpful

Thanks again!
Jan 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: cquante | last post by:
Okay, maybe I'm just not looking hard enough, but I could really use some source code. I found some that works with IE, but I want to be able to do the same with firefox if possible. I know I can...
2
by: jabberwhocky | last post by:
I have designed a website in IE which works perfectly, the problem is that when I look at it in the latest version of Mozilla/Firefox 2.0 the Table Background colour is not displayed, but only the...
26
by: mark | last post by:
The idea of this is very simle. The site is 800px wide and sits in the middle of the browser window, on either side of the site I want a different background image aligned against it. If I were...
2
by: SM | last post by:
Hello, How hard could it be to create the embeded youtube object in JavaScript DOM ? .... I've create the code and it works ok in Firefox but in IE7 i get an invalid argument error. Can...
7
by: Dayo | last post by:
Hello folks. Sorry if this seems a bit silly, I have no experience with this type of code. Here is a fading script for an Image Gallery I am looking to fix. It works with IE and Safari but not...
3
by: fulio pen | last post by:
Hello, I have a code that works on both the IE and Opera, but not the Firefox, and I cannot figure out the reason. Following is the page: http://www.pinyinology.com/test/span2.html And...
7
by: John Kotuby | last post by:
Hi all, I have created an ASPX page in VS 2008 that appears inside of an IFRAME inside a standard HTML page. Because it loads from an external site and is database driven, the first load takes a...
3
by: riggy | last post by:
So, I have an order form that works fine in IE but when you enter the info in Firefox and click the Submit Button, nothing happens. I am not sure if the button is not working or if there is a error...
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.