SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Detect whether radio button exists

    I am allowing users to choose which payment system they wish on a form. However if no deposit is required I remove this radio button and only display the full payment radio button. Problem is the function I am using to show the radio buttons (ie. turn disable = false) fails because the deposit radio button does not exist!!

    This is the function:

    function FlipBoxes() {
    if (document.Form2.PaymentType[1].checked) { document.Form2.PaymentAmount[1].disabled = false document.Form2.PaymentAmount[0].disabled = false } else { document.Form2.PaymentAmount[1].disabled = true document.Form2.PaymentAmount[0].disabled = true
    }
    }

    So how do i detect whether the radio button exists? I have tried:
    if (document.Form2.PaymentAmount[0])
    to no avail..

    Please help this is driving me crazy...

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try this function:
    Code:
    function doesRadioExist(radioName) {
      //radioName is the name of your radio button set
      var dr = document.getElementsByName(radioName);
      if (dr.length > 0) {
        return true;
      } else return false;
    }
    Sample usage:
    Code:
    var bPayment = doesRadioExist("PaymentAmount");
    //bPayment should be true or false depending on 
    //whether the radio button set exists
    NOTE: This function works in all DOM-compliant browsers, so if you have to support NN4 or IE4 it won't work in those browsers.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pretty close....
    Code:
    if (typeof document.Form2.PaymentAmount[0] != 'undefined')
    ::: certified wild guess :::


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •