/    Sign up×
Community /Pin to ProfileBookmark

Netscape problem

I am using the getElementsByTagName method with innerHTML property in a js function.

It works beautifully in IE, but won’t work in (at least) Netscape 6 or 7.

Can anyone tell me if the problem is that Netscape does not work with either or both of these elements?

Doug

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 25.2004 — NS6 & 7 should run this method also...

Can you post the part of the code with problems. Or better all the code, and isolate the part you think brings you problems?
Copy linkTweet thisAlerts:
@doug777authorFeb 25.2004 — The code searches for span tags that surround a price on the page in the format either (for example)

<span>US$24.50</span>

or if an alternative currency has been already been selected

<span>A$40.00 (US$24.50)</span>

sym contains the currency symbol - US$ A$ etc.

rate contains the exchange rate for that symbol.

A button on the page pops up a small window where the currency can be selected. When the 'go' button is clicked in the currency selection window, the currency changes to the one selected with US$ in parentheses if US$ is not the selected currency.

In IE it works reliably with no problems but in Netscape when you click the go button, nothing happens and the window does not close.

This is the function on the main page called by the currency window:

function NewText(sym, rate) {

for (i=0;i<document.getElementsByTagName('span').length;i++){

var price = document.getElementsByTagName('span')[i].innerHTML;

if(price.indexOf('(') == -1) {

var firstnum=price.search(/d/);

var pricenum=price.slice(firstnum);

}

else {

var firstnum=price.search(/(/)+4;

var pricenum=price.slice(firstnum, -1);

price=price.slice(firstnum-3, -1);

}

if(sym == "US$") {

var newprice=sym+pricenum;

}

else {

var cvtprc=Math.ceil((((pricenum)*1.02)/rate)*100)/100;

cvtprc=cvtprc+0.001;

cvtprc=""+cvtprc;

var decpnt=cvtprc.search(/./);

cvtprc=cvtprc.slice(0, decpnt+3);

var newprice=sym+cvtprc+" ("+price+")";

}

document.getElementsByTagName('span')[i].innerHTML=newprice;

}

}



This is the calling code in the currency window



function setCurrency() {

for(var i = 0; i < jcurrarray.length; i++) {

if (jcurrarray[i] == selectCurrency.value) {

currsym = jcurrarray[i+2];

currate = jcurrarray[i+3];

break;

}

}

writeCookie("currsym", currsym, 24);

writeCookie("currate", currate, 24);

opener.NewText(currsym, currate);

window.close();

}



jcurrarray contains the sym and rate for each currency in a database updated daily.



Hope this is clear enough and many thanks for your time.



Doug
Copy linkTweet thisAlerts:
@KorFeb 25.2004 — ..I would have built the array otherwise...

function NewText(sym, rate) {

[color=red]var price= new Array();[/color]

for (i=0;i<document.getElementsByTagName('span').length;i++){

var price[color=red][i][/color] = document.getElementsByTagName('span')[i].innerHTML;



... thus you have further price[i], and not price (which is the whole array, not each element) to search for...
Copy linkTweet thisAlerts:
@KorFeb 25.2004 — the same with

var firstnum

var pricenum

var newprice

Which, in my opinion, should have been set up as arrays also;


var firstnum = new Array();

var pricenum = new Array();

var newprice = new Array();

above the increment, and use like arrays elements

var firstnum[i]

var pricenum[i]

var newprice[i]



according to price[i] inside the increment...
Copy linkTweet thisAlerts:
@doug777authorFeb 25.2004 — Many thanks for your replies, but regret still has same problem in Netscape, although works fine in IE (without var on the array element calls).

Doug
Copy linkTweet thisAlerts:
@KorFeb 25.2004 — It might be a referenece problem also. NS needs complete referenece of the object, IE accept shortcuts (i.e. [i]id[/i].attribute or [i]name[/i].attribute), while NS needs all the tree, starting with document. or at least with form.)

1 what is jcurrarray? I don't see where is it set up as an array.

2. [color=red]window.[/color]opener.close();
Copy linkTweet thisAlerts:
@doug777authorFeb 25.2004 — 
  • 2. no change - works in IE not in Netscape


  • 1. jcurrarray is built by Cold Fusion from a database.


  • Here is code.

    <script language="JavaScript" type="text/javascript">var jcurrarray = new Array();</script>

    <cfoutput><cfloop from="1" to="#i#" index="j">

    <script language="JavaScript" type="text/javascript">jcurrarray[#j# - 1] = '#currArray[j]#';</script>

    </cfloop></cfoutput>
    Copy linkTweet thisAlerts:
    @doug777authorFeb 25.2004 — Just wondering if the problem lies in the select code. I have used a button element for the 'go' button, and originally I thought it should be within <form> tags, but this didn't work in IE so I took them out.

    Here is the code where customer chooses the currency:

    <select name="selectCurrency" id="selectCurrency">

    <cfoutput query="exchRates">

    <option value="#exchRates.CurrencyCode#"<cfif (#exchRates.CurrencyCode# EQ "USD")> selected</cfif>>#exchRates.CurrencyName#</option>

    </cfoutput>

    </select>

    <input name="closeWindow" type="button" id="closeWindow" value="Go" onclick="setCurrency()" />
    ×

    Success!

    Help @doug777 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...