Solved

Getting an undifined from input with a type=radio

Posted on 2004-08-17
3
325 Views
Last Modified: 2008-01-09
I am trying to validate that all questions are answered before I submit a page.  When I try and pull the value of the <input type="radio" id="touring" name="touring" value=1> and I have more then one Radio button I keep getting undefind and no value.  If i have only one radio button then i can get the correct value.
Javascript

function submitUpdateProduction()
      {
            str = document.frmLAStageTixRegistration.touring.value
            if (str.length < 1)
                  {
                        alert("Please answer if this is a touring production or not. " + str);
                        document.frmLAStageTixRegistration.touring.focus()
                        return false;
                  }
            document.frmLAStageTixRegistration.action = "../lastage/registration.asp?updateproduction=1";
            document.frmLAStageTixRegistration.method = "post";
            document.frmLAStageTixRegistration.submit();
            return true;
      }

HTML

<tr>
      <td colspan=3 class="reg10" valign="top" bgcolor=#ABDAE0>
            Is this a touring production?
      </td>
      <td class="reg10" valign="top" bgcolor=#ABDAE0>
            <input type="radio" id="touring" name="touring" value=1> &nbsp; Yes &nbsp;&nbsp;
            <input type="radio" id="touring" name="touring" value=0> &nbsp; No
      </td>
</tr>
0
Comment
Question by:eseyfried
[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
  • 3
3 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 350 total points
ID: 11823548
if you have more than one radio with the same name, then you need to treat it as an array:

str = document.frmLAStageTixRegistration.touring[0].value
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11823578
but I think what you want is not the value of the first radio, but the value of the checked one, correct?

if so ...

var checkedIndex = -1;

if ( document.frmLAStageTixRegistration.touring[0].checked==true )
   checkedIndex = 0;
else if ( document.frmLAStageTixRegistration.touring[1].checked==true )
   checkedIndex = 1;

if ( checkedIndex > -1 )
{
   str = document.frmLAStageTixRegistration.touring[checkedIndex].value;

...
}
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 11823601
actually, you can do it this way:

var checkedIndex = -1;

if ( document.frmLAStageTixRegistration.touring[0].checked==true )
   checkedIndex = 0;
else if ( document.frmLAStageTixRegistration.touring[1].checked==true )
   checkedIndex = 1;

if ( checkedIndex == -1 )
{
      alert("Please answer if this is a touring production or not. " + str);
      document.frmLAStageTixRegistration.touring.focus()
      return false;
}
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
Suggested Courses

624 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