SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Huntington Beach, CA
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript making Radio buttons required - help!!

    Helllo everyone, I have the following form and accompanying JavaScript setup but can not seem to get it to work.

    Here is what I have:
    Code:
    <script type="text/javascript">
    function ValidateEventForm()
    {
    
    btnChecked = false;
    for (i=0; i<document.EventForm[0].pass.length; i++)//get number of buttons in the group
    {
       if (document.EventForm[0].pass[i].checked) btnChecked = true; //see if current button is checked
    }
    
    if (!btnChecked) 
    {
      alert("Please select a Type of Expo Pass.");
      return false;
    }
    
    btnChecked = false;
    for (i=0; i<document.EventForm[0].d1_am.length; i++)//get number of buttons in the group
    {
       if (document.EventForm[0].d1_am[i].checked) btnChecked = true; //see if current button is checked
    }
    
    if (!btnChecked) 
    {
      alert("Please select a Day 1 Morning Session Tract.");
      return false;
    }
    
      }
    </script>
    
    
    	<form action="https://www.homex2007.com/register-confirm.php" method="post" name="EventForm" onSubmit="return ValidateEventForm();">
    
    
                  <td width="29%" colspan="2" style=" border-bottom: 1px solid #000000; "><p><strong>Regular Pricing <br>
        After Jan. 15, 2007</strong></p></td>
                </tr>
                <tr>
                  <td><br><p><strong> 
                    <input name="pass" type="radio" value="1 Day Pass" onClick="selected">
                  One-day Pass</strong></p></td>
                  <td><br><p><strong> $250.00</strong></p></td>
                  <td colspan="2"><br><p><strong> $350.00</strong></p></td>
                </tr>
                <tr>
                  <td><p style="padding-top:3px; "><strong>
                    <input name="pass" type="radio" value="2 Day Pass" onClick="selected">
                  Two-day Pass</strong></p></td>
                  <td><p><strong>$375.00</strong> </p></td>
                  <td colspan="2"><p><strong>$475.00</strong></p></td>
                </tr>
                <tr>
                  <td colspan="4"><br><p>One & Two day passes include Continental Breakfast, Lunch on Expo Floor, access to all Summit & Keynote Sessions, Expo Floor, Welcome Cocktail Reception
    
    and After Party at the Aquarium of the Pacific., You may register to attend all non-hosted events.</p></td>
                </tr>
                <tr>
                  <td><br><p><strong>
                    <input name="pass" type="radio" value="Expo Only" onClick="selected">
                  Expo Only Pass</strong></p></td>
                  <td><br>
                  <p><strong> $75.00</strong></p></td>
                  <td colspan="2"><br>
                  <p><strong> $100.00</strong></p></td>
                </tr>
                <tr>
                  <td colspan="4"><p>Expo Pass includes access to Expo Floor <strong>ONLY</strong> for both days.</p></td>
    I am not getting an error when the radios area not checked and it will let the user continue to the next page.

    Any help would be awesome!!

    Rob
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WebRob
    Code:
    for (i=0; i<document.EventForm[0].pass.length; i++)
    I am not getting an error when the radios area not checked and it will let the user continue to the next page.
    You are getting an error - it's indicated in the JavaScript console, which you ignore at your frustration.

    document.EventForm[0] == the first single element in document.EventForm, not an array.

    You need to address: document.EventForm.pass

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Huntington Beach, CA
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali
    You are getting an error - it's indicated in the JavaScript console, which you ignore at your frustration.

    document.EventForm[0] == the first single element in document.EventForm, not an array.

    You need to address: document.EventForm.pass
    Thank you, that worked perfectly. I had been using the console and it had an error I was unsure of....I know pretty much nothing about javascript.

    Now this form does what it is suppose to and prevents a person from moving on unless they fill out the form completely. I have pretty much the same validation on the previous page and it will let a user continue:

    http://www.homex2007.com/register.php

    I have checked the console and there are no errors.....any ideas on this one?

    Thank you again for your help.
    -Rob
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WebRob
    Thank you, that worked perfectly. I had been using the console and it had an error I was unsure of....I know pretty much nothing about javascript.

    Now this form does what it is suppose to and prevents a person from moving on unless they fill out the form completely. I have pretty much the same validation on the previous page and it will let a user continue:

    http://www.homex2007.com/register.php

    I have checked the console and there are no errors.....any ideas on this one?
    There certainly is an error in the console; if you press the button without entering anything you get: 'name.focus() id not a function'
    Code:
    function ValidateRegForm()
    {
        var prefix = document.RegForm.prefix;
        var fname = document.RegForm.fname;
        var lname = document.RegForm.lname;
        var bname = document.RegForm.bname;
        var company = document.RegForm.company;
        var address = document.RegForm.address;
        var city = document.RegForm.city;
        var state = document.RegForm.state;
        var zip = document.RegForm.zip;
        var country = document.RegForm.country;
        var email = document.RegForm.email;
    
        if (prefix.value == "")
        {
            window.alert("Please enter a Prefix.");
            name.focus();
            return false;
        }
    Several tests are calling name.focus, which is undefined. You probably want to refer to fname.

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2005
    Location
    Huntington Beach, CA
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was my stupid oversight. Thank you for your help!!
    Rob
    Pier Marketing ◄ Printing and Marketing Collateral - Order Online
    Pier Technologies ◄ Web Development & IT Solutions
    And That's News? ◄ My NEW Blog!!


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
  •