/    Sign up×
Community /Pin to ProfileBookmark

Simple Code..Variable Showing Undefined..Why?

Hello.

Can anyone tell me why in this simple code my variable “the_values” is showing undefined in Firebug? or better yet..why it’s not doing anything…

[CODE]
<html><head><title>Whatever</title>
<script type=”text/javascript”>

function attachHandlers(){
var the_button = document.getElementById(“the_click”);
the_button.onclick=showPicks();
}

function showPicks(){
var the_values = document.getElementsByName(“the_numbers”).value;

var my_selections = new Array();

for (var i=0; i<the_values.length; i++){
my_selections= the_values[i];
}

alert(my_selections);

}
</script></head>

<body onload=”attachHandlers()”>
<form>
<input type=”textbox” name=”the_numbers” size=”1″ value=”1″>
<input type=”textbox” name=”the_numbers” size=”1″ value=”2″>
<input type=”textbox” name=”the_numbers” size=”1″ value=”3″>
<input type=”textbox” name=”the_numbers” size=”1″ value=”4″><br>
<input type=”button” value=”checknumbers” size=”1″ id=”the_click”>
</form>
</body>
</html>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsDec 16.2008 — [CODE]<html><head><title>Whatever</title>
<script type="text/javascript">

function attachHandlers(){
var the_button = document.getElementById("the_click");
the_button.onclick=showPicks;
}

function showPicks(){
var the_values = document.forms[0].the_numbers;

var my_selections = new Array();

for (var i=0; i<the_values.length; i++){
my_selections= the_values[i];
}

alert(my_selections);

}
</script></head>

<body onload="attachHandlers()">
<form>
<input type="textbox" name="the_numbers" size="1" value="1">
<input type="textbox" name="the_numbers" size="1" value="2">
<input type="textbox" name="the_numbers" size="1" value="3">
<input type="textbox" name="the_numbers" size="1" value="4"><br>
<input type="button" value="checknumbers" size="1" id="the_click">
</form>
</body>
</html>[/CODE]
×

Success!

Help @JohnBeason 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...