/    Sign up×
Community /Pin to ProfileBookmark

function issue

Hi,

I’m quite new to javascript (but I’m getting better)

My problemn is following :

I got a page with a form and two <select> tags within. Second is updated regarding actions and value on the first one

the first

[CODE]echo “<select STYLE=’width: 100px;’ name=’avatar_class’ size=’1′ onchange=’showValue(this);’ onmouseup=’showValue(this);’>”;[/CODE]

the second

[CODE]echo “<select name=’avatar_spec’ size=’1′ STYLE=’width: 100px;’ disabled>n”;[/CODE]

Begin of function is :

[CODE]function showValue( b )
{ var f = b.form;
var sel = f.elements[‘avatar_class’];
var spec = f.elements[‘avatar_spec’];
spec.disabled=false;
RemoveAllSpec(spec);
………….[/CODE]

This works fine upon change or mouseup on the first select tag.

But….

I would like this function to run at page load. I then put within my code, at the end of the file :

[CODE] echo “<SCRIPT LANGUAGE=’javascript’>”;
echo “showValue(this);”;
echo “</SCRIPT>”;[/CODE]

Function is called, but the “this” do not seem to be the same as when function called by events on first tags.

Firebug returns me that error

[CODE]f has no properties
[Break on this error] var sel = f.elements[‘avatar_class’];[/CODE]

Wath am I doing wrong ?

Thx in advance,

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 06.2007 — You should refer the element ([B]this[/B] is the self reference for the element which suport event and trigger a function). And you need to call the function onload. And use [I]type[/I] for the script, not the deprecated [I]language[/I]
<i>
</i>echo "&lt;script type="text/javascript"&gt;";
echo "onload=function(){showValue(document.getElementsByName('avatar_spec')[0]);}";
echo "&lt;/script&gt;";
Copy linkTweet thisAlerts:
@civetteauthorSep 06.2007 — Yes, it works !

Thx
Copy linkTweet thisAlerts:
@KorSep 06.2007 — You bet!?
×

Success!

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