DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    2

    javascript: validate radio button

    I am just wanting to check to see if either radio button is selected. Right now, if they select yes, then the errMessage doesn't display, which is want I want. However, if they select no, if will. I only want the errMessage if they don't select either yes or no. Any suggestions would be appericated.

    Here's the basic code:

    function doSubmit()
    {
    var errMessage=""
    if (!document.applynow.cemp1.checked)
    {
    errMessage = errMessage + "\n - Please answer if employer 1 of Employment History is your current employer.";
    }
    if (document.applynow.emp1position.value=="")
    {
    errMessage = errMessage + "\n - Please enter your last position title of employer 1 of Employment History.";
    }
    if (errMessage != "")
    {
    errMessage = "The following filled need to be completed" + errMessage
    alert(errMessage);
    }
    else{
    document.applynow.submit();
    }
    }

    -------
    <form name="applynow" action="thankyou.asp" method="post">

    Is this your current employer:
    Yes: <input type="radio" name="cemp1" value="Yes" id='one' />
    No: <input type="radio" name="cemp1" value="No" id='two' />

    Job position(s): <input type="text" name="emp1position" size='40' />

    <input name="cmdSubmit" type="button" value="Submit Application" onclick="doSubmit()" >
    </form>
    Last edited by mrenefrancisco; 04-16-2008 at 04:18 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    Instead of
    if (!document.applynow.cemp1.checked)

    try giving

    Code:
    if(!document.getElementById('one').checked && !document.getElementById('two').checked)

Similar Threads

  1. radio button inside datagrid
    By Balaji N.S in forum .NET
    Replies: 3
    Last Post: 02-17-2007, 02:36 PM
  2. UserControl from Radio Button
    By spiffycrony in forum .NET
    Replies: 0
    Last Post: 11-01-2006, 09:44 PM
  3. JavaScript IE radio button problems
    By barrel in forum Web
    Replies: 1
    Last Post: 10-23-2006, 06:01 AM
  4. Replies: 0
    Last Post: 02-10-2006, 10:15 AM
  5. Replies: 2
    Last Post: 04-28-2005, 09:31 AM

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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links