/    Sign up×
Community /Pin to ProfileBookmark

select onChange() doesn’t activate

Hi,

A static version of the dynamic page in question is available here [url]http://www.heath-eu.com/test[/url]

As you can see, this page has 15 rows, each with a drop down per day- it’s used for recording hours spent on projects.

Each of the select objects start like this:

<select name=’[i]day[/i]_[i]count[/i]‘ id=’[i]day[/i]_[i]count[/i]‘ onChange=”altotal(‘[i]day[/i]‘)” size=1>

EG

[code=php]<select name=’thu_2′ id=’thu_2′ onChange=”altotal(‘thu’)” size=1>
<select name=’sat_7′ id=’sat_7′ onChange=”altotal(‘sat’)” size=1>
<select name=’mon_12′ id=’mon_12′ onChange=”altotal(‘mon’)” size=1>[/code]

The select statements are made in PHP by the following function

[code=php]function timedrop($dropname)
{
$day = substr($dropname, 0, 3);
$returner = “<select name=’$dropname’ id=’$dropname’ onChange=”altotal(‘$day’)” size=1>”;

$counter = 0;
while ($counter < ‘24.25’)
{
$returner .= “<option value=$counter>$counter</option>”;
$counter = $counter + 0.25;
}

$returner .= “</select>”;

return $returner;
}[/code]

Looking at the above link, only the first row and mon, tue, wed, thur of row 2 actually invoke the function, even though they’re all made from the same code.

Any reason why this should be?

Thanks in advance.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 27.2006 — This may be a problem:if (thishours > "0" && thisday == today)[/quote]Try:if ((thishours &gt; "0") &amp;&amp; (thisday == today))
If that doesn't help, then re-think your use of EVAL statements. None of them have to be evals, they can all be replaced with more conventional methods. For example:
var currenthours = parseFloat(eval("document.time.h" + thisday + ".value"));[/quote]could becomevar currenthours = parseFloat(document.time["h" + thisday].value);
Copy linkTweet thisAlerts:
@CharlesNov 27.2006 — While I certainly support the erradication of all unnecessary uses of the evil eval function, I don't think that either is the problem.

I seem to recall that "&&" and "||" preside over the comparative operators. They are evaluated second.
Copy linkTweet thisAlerts:
@DJParaDoXauthorNov 27.2006 — I understand about removing the EVALs and will get to that now- I only added them at the start when nothing was working.

To be clear, the function does work fine. When any of the top row selects are changed, or mon to thur on the 2nd row the function is invoked.... but this doesn't happen with any of the others.

I'll remove the EVALs now

Any other ideas?
Copy linkTweet thisAlerts:
@gil_davisNov 27.2006 — These changes seemed to fix the addition:
for (iCount = "1"; iCount &lt; "15"; iCount++) // was "16"
{
// Gets the value for the currently allocated hours
// var thisdrop = eval("document.getElementsByTagName("select")[" + iCount + "].name");
var thisdrop = thisday + "_" + iCount;
//thishours = parseFloat(eval("document.time." + thisdrop + ".value"));
thishours = parseFloat(document.time[thisdrop].value);
...
Copy linkTweet thisAlerts:
@DJParaDoXauthorNov 27.2006 — Thanks, I've removed all the eval statements now.

I don't quite know why, maybe someone could tell me for my learning, but removing them has corrected the initial problem of only some of the selects working.

Thanks again,

James
Copy linkTweet thisAlerts:
@gil_davisNov 27.2006 — Charles' comment that EVAL is EVIL echoes my sentiment, but I don't have an explanation of the behaviour for you. Glad you got it straight, though!
×

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.27,
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,
)...