A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Using radio buttons with JavaScriptThis tutorial will show how to make a textbox display a text depending on which radio button was checked. |
On Monday, September 4th 2006 at 02:05 PM By Sorin Sodolescu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.1 with 109 votes) |
||
|
Contextual Ads
More JavaScript Resources
Advertisement
In this tutorial we will see how to make a textbox display a text, depending on what radio button is checked. <html> |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current CommentsSo far, I have no idea on how to read radiobutton values in Greasemonkey scripts.
I really would like to see a version of the script that is compatible with Firefox\'s XPCNativeWrappers.
Anyone have some good ideas?
gochii
I did it in an other way...but still the same result
<html>
<head>
<script type="text/javascript">
function check(sport)
{
document.getElementById("answer").value=sport
}
</script>
</head>
<body>
<p>What's your favorite sport?</p>
<form>
<input type="radio" name="sport" onclick="check(this.value)" value="Basketball">Basketball<br />
<input type="radio" name="sport" onclick="check(this.value)" value="Football">Football<br />
<input type="radio" name="sport" onclick="check(this.value)" value="Baseball">Baseball<br />
<input type="radio" name="sport" onclick="check(this.value)" value="Soccer">Soccer<br />
<br />
Your favorite sport is: <input type="text" id="answer" size="20">
</form>
</body>
</html>
Hi Kadrus
Yes, putting the "Your favourite sport is: " text in the body and calling the function by clicking the radio button saved you from writing some extra code. That's great! But the point of this tutorial was to introduce beginners to for loops, arrays and obviously radio buttons. Nevertheless, congratulations for writing shorter, more efficient code!
fdbgdbgdf
dsfdsfds
We can use this for other validation
<script type="text/javascript">
<!--
function validForm()
{
var t="check"
for (i=0; i<document.myform.sports.length; i )
{
if (document.myform.sports[i].checked==true)
{
t =t document.myform.sports[i].value
}
}
if (t=="check"){
alert("You should fill all fields properly");
return false;
}
else {
return true;
}
}
-->
</script>
<form name="myform">
<input type="radio" name="sports" value="Fotball" />Football<br />
<input type="radio" name="sports" value="Hockey" />Hockey<br />
<input type="radio" name="sports" value="F1" />F1<br />
<input type="radio" name="sports" value="Basketball" />Bascketball<br />
<input type="radio" name="sports" value="Tennis" />Tennis<br />
<input type="radio" name="sports" value="Golf" />Golf<br />
<input type="button" value="VOTE" onClick="validForm()" /><br>
</form>
Thanx Kadrus!!!!
Thanx Kadrus!!!!
wst site very poor site
Hi...
i have one query...if on clicking radio button I want all the value related to that record,thn how can we achieve it..
for example:
when I click on 1st radio button I should have all (username,userid,address,zip,city,country)these values to be displyed on the screen....
xvc b
xvc b
xvc b
@vrushali
u shud look into jQuerry, its gives u neat methods to do that
hi
this s a wonderful tutorial for me.it helps me a lot.
hi
this s a wonderful tutorial for me.it helps me a lot.
hi
this s a wonderful tutorial for me.it helps me a lot.
hi
this s a wonderful tutorial for me.it helps me a lot.
hi
this s a wonderful tutorial for me.it helps me a lot.
hi
this s a wonderful tutorial for me.it helps me a lot.
Obviously you haven't gotten to writing an anti-bot form validation script. ;P
why doesn't water sink or drown ?
we neeed when we click radio button it show result in dialog box window
Hi..
This is Good tutorial for me.
But i want to chane the valu of the asp label control onclick of the radio button using javascript function.
Please Send me the Solution..
Thanx..
I do'nt think it is true....
What if you want to check multiple group of radio buttons....
where name="" differs to each group.
Thanx alot,It is working yaar,I was using the getElementsByName method,thanx again
Thanx alot,It is working yaar,I was using the getElementsByName method,thanx again
Related Tutorials
Related Source Code
JavaScript Job Search