View Full Version : validating radiobuttons and textbox

02-11-2007, 08:52 PM

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".


<script language="javascript">

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


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

alert("Please Enter Your First Name");
return false;
<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">

Philip M
02-12-2007, 07:31 AM
It works fine for me in IE. I don't see anything wrong.

02-12-2007, 04:01 PM
you need to give this element an ID - "getElementById"

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

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