/    Sign up×
Community /Pin to ProfileBookmark

RAdioButton Values

Can someone please tell me why this script always produces an output of undefined No matter which radiobutton I press

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”JavaScript”>
function showgame()
{
var frm = document.forms[‘form1’];
frm.textfield.value = frm.RG1.value;

}

</script>
</head>

<body>
<p>&nbsp; </p>
<form name=”form1″ method=”post” action=””>
<p>&nbsp;</p>
<p>
<label></label>
</p>
<p>
<label>
<input type=”radio” name=”RG1″ value=”D”>
DTC</label>
Input
<input type=”text” name=”textfield”>
<br>
<label>
<input type=”radio” name=”RG1″ value=”M”>
MIA</label>
<br>
<label>
<input type=”radio” name=”RG1″ value=”L”>
LNC</label>
</p>
<p>
<input type=”Button” name=”Button” value=”Button” onClick=”showgame()”>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
<p>
<label></label>
</p>
<p>
<label></label>
<br>
</p>
<p>&nbsp; </p>
</body>
</html>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannJan 06.2004 — Hi!

You could use this:
<i>
</i>&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
function showgame()
{
var frm = document.forms['form1'];
for (var i = 0; i &lt; frm.RG1.length;i++){
if (frm.RG1[i].checked==true){
frm.textfield.value = frm.RG1[i].value;
}
}
}
//--&gt;
&lt;/script&gt;

Cheers - Pit
Copy linkTweet thisAlerts:
@requestcodeJan 06.2004 — Or this:

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">

function showgame()

{

var frm = document.forms['form1'];

for(i=0;i<frm.length;i++)

{

if(frm.elements[i].type=="radio")

{

if(frm.elements[i].checked)

{frm.textfield.value = frm.elements[i].value;}

}

}



}



</script>

</head>



<body>

<p> </p>

<form name="form1" method="post" action="">

<p> </p>

<p>

<label></label>

</p>

<p>

<label>

<input type="radio" name="RG1" value="D">

DTC</label>

Input

<input type="text" name="textfield">

<br>

<label>

<input type="radio" name="RG1" value="M">

MIA</label>

<br>

<label>

<input type="radio" name="RG1" value="L">

LNC</label>

</p>

<p>

<input type="Button" name="Button" value="Button" onClick="showgame()">

</p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

</form>

<p>

<label></label>

</p>

<p>

<label></label>

<br>

</p>

<p> </p>

</body>

</html>
Copy linkTweet thisAlerts:
@oleragJan 06.2004 — And the reason why your getting an undefined is your not

referencing a radio group element as the other examples

provided are.
Copy linkTweet thisAlerts:
@trsandsauthorJan 06.2004 — Thanks........
×

Success!

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