Solved

How can I dynamic check a radio button?

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

810 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