Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validating radiobuttons and textbox

    hi,

    i want to validate the radiobuttons and textbox so that the user have to select the one radiobutton(ex:category) and enter his name in textbox and press submit button.by using the following code when i press submit button with out selecting anything it is displaying a alert "enter category",ok after i select one category and press submit button it is again asking select category but i need alert "please enter your name".

    thanks
    mrjameer

    <head>
    <script language="javascript">


    function validate()
    {
    if (document.frm.radiogroup1[0].checked==false)
    {
    alert("Select catagory!");
    return false;
    }

    else

    if(document.getElementById("firstname").value == "")

    {
    alert("Please Enter Your First Name");
    document.getElementById("firstname").focus();
    return false;
    }
    }
    </script></head>
    <body>
    <form name ="frm" method="post" action="register_forms.php" onsubmit="return validate(this);">

    Category-4<input type="radio" name="radiogroup1" value="category4" id="r4">
    Category-3<input type="radio" name="radiogroup1" value="category3" id="r3">
    Category-2<input type="radio" name="radiogroup1" value="category2" id="r2">
    Category-1<input type="radio" name="radiogroup1" value="category1" id="r1">
    <input type="textbox" name="firstname">
    <input type="submit" value="submit">
    </form></body>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    It works fine for me in IE. I don't see anything wrong.

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need to give this element an ID - "getElementById"

    <input type="textbox" name="firstname">

    <input type="textbox" name="firstname" id="firstname">


  •  

    Posting Permissions

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