/    Sign up×
Community /Pin to ProfileBookmark

radio button stuff

Well, this is what happens when you try to work beyond your means. I’m trying to do a questionnaire using radio buttons. The questionnaire has four questions with four possible responses to each. Ultimately I would like to assign certain combinations to trigger text responses…for now I am just trying to identify the boxes that have been checked by writing their values to a new page. I’m sure the if statement is horribly off…any direction on how I could get this going properly is hugely appreciated…

<script type=”text/javascript”>
function getcode()
{
for(varname=0;varname<5;varname+=1)
{
if (document.form[varname].name[varname]==document.form[varname].name[varname].checked)
{
document.write(document.form[varname].name[varname]);
}
else
{
document.write(“not selected”);
}
}
}

</script>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisNov 29.2006 — First, an adjustment:
[CODE]
<script type="text/javascript">
function getcode()
{
for(varname=0;varname<5;varname+=1)
{
[COLOR=Blue]if ([/COLOR]document.form[varname].name[varname].checked[COLOR=Blue])[/COLOR]
{
document.write(document.form[varname].name[varname][COLOR=Blue].value[/COLOR]);
}
else
{
document.write("not selected");
}
}
}
</script>[/CODE]

Then, I question the fact that you are varying both the form name and the field name. It also looks like you have named your form as "form" and this is not a good practice. Many questions will be answered if you also post some examples of your actual HTML.
Copy linkTweet thisAlerts:
@johnnyblotterauthorNov 29.2006 — hmm, I though form was a property of the document object. I have named my forms (not) form but I thought I could access the form array through document.form[]. I'm trying to print to the screen the name values and corresponding forms that have been checked. I will post the html, thanks...
Copy linkTweet thisAlerts:
@so_is_thisNov 29.2006 — Then you wanted document.form[B][COLOR=Blue]s[/COLOR][/B] -- not document.form
×

Success!

Help @johnnyblotter 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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