Solved

How can I dynamic check a radio button?

Posted on 2002-05-03
4
172 Views
Last Modified: 2006-11-17
I have serveral radio button and a field, based on user input, I want to dynamic check the corresponding radio button, is it possible?
0
Comment
Question by:huixu01
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 100 total points
ID: 6988777
yes, but please provide more details ... what user input?  Can you show us the code for your form?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6988831
Basic testing for radios:

<script language="JavaScript">
<!--
function testrad()
{
   obj=document.myform.rads;
   for (i=0;i<obj.length;i++)
   {
      if (obj[i].checked)
      {
         alert('radio '+i+' is checked with a value of '+obj[i].value);
         return;
      }
      alert('No radio has been checked')
   }
}
//-->
</script>

this assumes:

<form name="myform">
   <input type="radio" name="rads" value="A">
   <input type="radio" name="rads" value="B">
   <input type="radio" name="rads" value="C">
   <input type="radio" name="rads" value="D">
</form>

Now if you post a little more detail of what you need, or your code, we will be happy to supply the detail you need.

Cd&
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6988914
Example:

<script language="javascript">
function checkCorresponding(fObj)
{
   val = fObj["myval"].value;
   rObj = fObj["rad"];
   switch(val)
   {
      case "val1":
         rObj[0].checked=true;
         break;
      case "val2":
         rObj[1].checked=true;
         break;
      case "val3":
         rObj[2].checked=true;
         break;
      case "val4":
         rObj[3].checked=true;
         break;
   }
}
</script>

<form name="myform">
 <input type=text onkeyUp="checkCorresponding(this.form)" name="myval">
 <input type=radio name="rad">
 <input type=radio name="rad">
 <input type=radio name="rad">
 <input type=radio name="rad">
</form>
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6988915
I agree though with keK and Cd&. please provide more input
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now