Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I dynamic check a radio button?

Posted on 2002-05-03
4
Medium Priority
?
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

705 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