/    Sign up×
Community /Pin to ProfileBookmark

help to newbie (very very newbie)

Hello friends. I need to select checkboxes in a webpage and get the selected values in a textarea.

I´m working with this code and functions ok,but does not fit exactly to my needs. With this code, independently of the order I click on the checkboxes, the selected values always appear in the same order they had as displayed in the checkboxes ( for example if I randomly click box5, box1, box3 , them appear in the textarea ordered as box1, box3, box5), but it would be better for me not to get the values in the textarea in the same order they are displayed in the checkboxes, but in the same order I click on them (for example if I click box5, box1, box3 , I would like them to appear in the textarea ordered as box5, box1, box3), I´m sorry because my inability to solve something that surely is basic and simple. Anybody could help me? Thanks in advance!?

<script language=”JavaScript”> function valores()
{
document.forms[‘formulario’][‘area’].value=””;
for(c=1; c<=300; c++)
{
if (document.forms[‘formulario’][‘box’+ c].checked==true)
{
document.forms[‘formulario’][‘area’].value=document.forms[‘formulario’][‘area’].value +document.forms[‘formulario’][‘box’+c].value + “”; }
}
}
</script>
<br>
<form name=”formulario” action=”nuevo.html” method=”get”>

<input value=”Aerofagia. ” name=”box1″ onclick=”valores()” type=”checkbox”>Aerofagia.<br>

<input value=”Afasia. ” name=”box2″ onclick=”valores()” type=”checkbox”>Afasia. <br>

<input value=”Afasia motora. ” name=”box3″ onclick=”valores()” type=”checkbox”>Afasia motora.<br>

<input value=”Afasia sensitiva. ” name=”box4″ onclick=”valores()” type=”checkbox”>Afasia sensitiva.<br>

<input value=”Agitaci&oacute;n. ” name=”box5″ onclick=”valores()” type=”checkbox”>Agitaci&oacute;n. <br>

<textarea name=”area” rows=”50″ cols=”50″></textarea></form>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@andy21aaNov 18.2008 — Try this, not very elegant but I'm trying to fit this in while working.

[CODE]<script language="JavaScript">
var list = [];
function valores(elem)
{
if (elem.checked)
list.push(elem.value);
else
{
for (var i = 0; i < list.length; i++)
{
if (list[i] == elem.value)
list.splice(i, 1);
}
}
document.forms['formulario']['area'].value = '';
for (var i = 0; i < list.length; i++)
document.forms['formulario']['area'].value += list[i] + ' ';
}
</script>
<br>
<form name="formulario" action="nuevo.html" method="get">

<input value="Aerofagia. " name="box1" onclick="valores(this)" type="checkbox">Aerofagia.<br>

<input value="Afasia. " name="box2" onclick="valores(this)" type="checkbox">Afasia. <br>

<input value="Afasia motora. " name="box3" onclick="valores(this)" type="checkbox">Afasia motora.<br>

<input value="Afasia sensitiva. " name="box4" onclick="valores(this)" type="checkbox">Afasia sensitiva.<br>

<input value="Agitaci&oacute;n. " name="box5" onclick="valores(this)" type="checkbox">Agitaci&oacute;n. <br>

<textarea name="area" rows="50" cols="50"></textarea></form> [/CODE]
Copy linkTweet thisAlerts:
@tortadeaceiteauthorNov 19.2008 — Thanks a lot Andy21aa. This code fits perfectly to my needs. Yor are very kind. Thanks again.
×

Success!

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