SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2003
    0 Post(s)
    0 Thread(s)

    Simple Java Script Function Testing Value of Radios

    Can someone tell me what's wrong with this code? The function seems to work fine, but the radios are returning other than "yes" even though both are selected as "yes":

    <link rel="stylesheet" type="text/css" href="triCounty.css" />
    <title>Tri-County Vending Gainesville Fl.</title>
    <script type="text/javascript" language="Javascript">
    function test_radios (){
    if (document.vending.purchase1.value=="yes" && document.vending.purchase2.value=="yes"){
    document.vending.results.value="You qualify";
    document.vending.results.value="You do not qualify";



    <table align="center" border="0" cellpadding="10" width="100%">
    <form name="vending">
    <td colspan="2"><h1 class= "centerheading">Tri-County Vending</h1></td>

    <dd class="green">Tri-County Vending</dd>
    <dd class="green">7210 S.W.45th.Place #2</dd>
    <dd class="green">Gainesville Fl.32608</dd>
    <dd class="green">Phone352) 395-7594</dd>
    <dd class="green">Email:</dd>
    <hr />
    <td><img src= "images/Combo.gif" alt="picture of our snack machine" width="120" height="190" /></td>

    <li>We supply the machine at no charge</li>
    <li>We fill the machine</li>
    <li>Machine is a snack soda combination</li>
    <li>Machine can be seperated into soda only or snack only</li>
    <li>Takes the same space as a small refrigerator</li>
    <li>Name brand Soda's and Snacks at reasonable prices</li>
    <li>Looks simular to picture</li>

    <input type="button" value="Press to see if you qualify" name="R" onclick="test_radios();"><br /><br />
    <textarea name="results" rows="1" cols="30"></textarea><br />
    <p class="green">Only if you qualify will you be allowed to continue. If you qualify you will be re-directed to a form page.
    Please fill out if you want us to contact you.</p>
    <input type="Reset" value="Reset" name="RESET">
    <td><p class="green">Please fill out the form. When you click on the "see if you qualify button" you will know
    instantly if, you qualify for one of our machines.<p/>

    <h5>1) Is your business in Alachua, Levy, or Gilchrist county Fl.</h5>
    <input type="radio" name="purchase1" value="yes">Yes
    <input type="radio" checked name="purchase1" value="no">No<br />

    <h5>2) Do you have 10 or more employee's</h5>
    <input type="radio" name="purchase2" value="yes">Yes
    <input type="radio" checked name="purchase2" value="no">No<br />




  2. #2
    SitePoint Zealot
    Join Date
    Jul 2002
    Fort Lauderdale
    0 Post(s)
    0 Thread(s)
    You just need to reference the radio elements like an array. This will make sure both of the yes radio buttons are checked.
    if (document.vending.purchase1[0].checked==true && document.vending.purchase2[0].checked==true )
    Last edited by Vasudevelopa; Mar 20, 2003 at 12:39. - A Fort Lauderdale based multimedia company.


Posting Permissions

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