473,654 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getE lementById('fld[2]');
</script>
<script type="text/javascript">fun ction addOption(){

myList = document.getEle mentById('lfld' );
document.forms[0].elements['lfld'].value =
document.forms[0].elements['lfld'].value + x.options[x.selectedIndex].text +
'\n';
}
</script>
<input onclick="addOpt ion()" 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('p age1.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 2357
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.getE lementById('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['elementNAMEnot ID'];
</script>
<script type="text/javascript">fun ction addOption(){

myList = document.getEle mentById('lfld' );
document.forms[0].elements['lfld'].value =
document.forms[0].elements['lfld'].value + x.options[x.selectedIndex].text +
'\n';
}
</script>
<input onclick="addOpt ion()" 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('p age1.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.javas cript 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.getE lementById('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">fun ction addOption(){

myList = document.getEle mentById('lfld' );
document.forms[0].elements['lfld'].value =
document.forms[0].elements['lfld'].value + x.options[x.selectedIndex].text +
'\n';
}
</script>
<input onclick="addOpt ion()" 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('p age1.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*********@in valid.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.getE lementById('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.getEle mentsByName('fl d[2]')[0];

.... The following code should open a new window sending it a parameter to open:
'onClick' => "window.open('p age1.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/rasterTriangleD OM.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.getE lementById('fld[2]');


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

<input type="text" name="teletubbi e" />

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

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

- use document.forms. YourForm["fld[2]"]...
- add the id property (name="teletubb ie" id="teletubbie" )
- or change the document.getEle mentById for document.getEle mentsByName

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['elementNAMEnot ID'];

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
2759
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 create an extension in firefox, but I don't understand how I can get that extension to call my program. I want to be able to right-click on text on a web page, and in the right-click menu that comes up, I want to be able to select my program. ...
2
4731
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 overall page background colour of black. The problem is now is that I cannot see any of the links or page content. I have tried setting the bgcolour in the TD, TR and Table tags. The website is www.justasiam.com.au. Please help??? I am a...
26
2586
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 doing this with table based layout the code would be as follows: <head> <style type="text/css"> #bgleft { background: url(left_half_circle.gif) right top repeat-y;
2
2059
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 someone tell me what im doing wrong? For reference, this is the embebed youtube video object:
7
1566
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 with Firefox and Netscape. Actually, when I say it doesn't work, I mean you have to refresh the page before the fade happens and once that is done once, it works on that image. for that session. Here is the code: // Fade In Script
3
1209
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 following is the code: function chinText()
7
2221
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 few seconds. As a result I have placed an absolutely positioned <DIVelement that is built into the HTML page that uses an animated GIF and a "Please Wait" message. When the IFRAME finishes loading a javascript function is called to change the...
3
1734
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 in the Javascript code. Regardless, I have one of those situations where I can look at this all day and see nothing. Please help! TIA..... When you click the submit buttn, I do a form fields error check . If there are errors, you get a alert. If no...
3
5551
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 numeric strings { var strValidChars = "0123456789.-"; var strChar; var blnResult = true;
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8707
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.