/    Sign up×
Community /Pin to ProfileBookmark

Works in FF not IE

This page here [url]www.heath-eu.com/TEST[/url] is a static extract of a page on our intranet.

The code, as you can see, just adds up the drop downs for each day, adds that number to the ‘already allocated’ number, and dumps the result back to the screen.

It works fine in firefox, but gives an error in IE.

Can anyone shed any light? The maths/ looping side of things are fine, it’s just the outputting that’s not working.

Here is the script:

[CODE]
<script type=”text/javascript”>
function altotal(thisday)
{
// Initialises variables
var iCount = 1;
var temphours = 0;
var currenthours = parseFloat(eval(“document.time.h” + thisday + “.value”));

// Counts through all the drop downs, adding the hours up
for (iCount = “1”; iCount < “16”; iCount++)
{
// Gets the value for the currently allocated hours
var thisdrop = eval(“document.getElementsByTagName(“select”)[” + iCount + “].name”);
thishours = parseFloat(eval(“document.time.” + thisdrop + “.value”));

// Adds up all the newly chosen hours if they’re for the correct day
today = thisdrop.substring(0,3)
if (thishours > “0” && thisday == today)
{
temphours = parseFloat(temphours) + parseFloat(thishours);
}
}

// Works out total hours by adding the above count to the number already saved
temphours = parseFloat(currenthours) + parseFloat(temphours);

// Puts the new hour total into the span
var daytoreplace = eval(“document.getElementById(“al” + thisday + “”)”);
replaceText(daytoreplace, temphours);
}

function replaceText(el, text)
{
if (el != null)
{
clearText(el);
var newNode = document.createTextNode(text);
el.appendChild(newNode);
}
}

function clearText(el)
{
if (el != null)
{
if (el.childNodes)
{
for (var i = 0; i < el.childNodes.length; i++)
{
var childNode = el.childNodes[i];
el.removeChild(childNode);
}
}
}
}
</script>
[/CODE]

IE errors on this bit

[CODE]var newNode = document.createTextNode(text);
el.appendChild(newNode);[/CODE]

My knowledge of JS is minimal, I mainly code in PHP, so please, dumb it down a little ?

Thanks in advance,

James

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzNov 09.2006 — I tried it in IE but didn't get any errors. What error message did it give you?

Why did you quote the numbers in the for() loop?

Why don't you just access the value the first time instead of using two statements, including one that uses eval()?
var thisdrop = eval("document.getElementsByTagName("select")[" + iCount + "].name");
thishours = parseFloat(eval("document.time." + thisdrop + ".value"));

Don't use eval(). It's very slow.
Copy linkTweet thisAlerts:
@DJParaDoXauthorNov 10.2006 — Does it work for you and put the calculated number on the screen in the 'allocated' row? The message that I get is:

[img]http://www.heath-eu.com/test/error.jpg[/img]

Line 177 is:

<i>
</i>167 var daytoreplace = eval("document.getElementById("al" + thisday + "")");
168 replaceText(daytoreplace, temphours);
169}
170
171function replaceText(el, text)
172{
173 if (el != null)
174 {
175 clearText(el);
176 var newNode = document.createTextNode(text);
177 el.appendChild(newNode);
178 }
179}


While I don't disagree (or rather know any better) that eval() is slow, this isn't going to be a massively used system. Also, this is pretty much the first JS I've written without guidance, so I'm on a steep learning curve, using what I've found works, rather than what's best. I'd just like to get it work for now, then optimise it later.

thanks,

James
×

Success!

Help @DJParaDoX 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.18,
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,
)...