Solved

How can I dynamic check a radio button?

Posted on 2002-05-03
4
174 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

896 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

17 Experts available now in Live!

Get 1:1 Help Now