Solved

How can I dynamic check a radio button?

Posted on 2002-05-03
4
180 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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pass asp session variable to a js function in an asp script 6 27
Hide Table in merge 3 29
Google Analytics setup 5 50
CORS Error from Chrome, but FireFox is OK 1 77
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

789 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