Radio button Validation

Radio button Validation

Hi..

How to validate radio button in java?if the radio button is not selected an error message should be given... Please help...

View Answers

February 11, 2012 at 3:10 PM

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class RadioButtonValidation{
JTextField text;

public static void main(String[] args) throws Exception{
new RadioButtonValidation();
}

public RadioButtonValidation(){
JFrame f = new JFrame();
f.getContentPane().setLayout(null);
JLabel lab = new JLabel("Gender");
final JRadioButton Male,Female;
ButtonGroup radioGroup=new ButtonGroup();
Male=new JRadioButton("Male");
radioGroup.add(Male);
Female=new JRadioButton("Female");
radioGroup.add(Female);
JButton button=new JButton("Submit");
lab.setBounds(50,20,70,20);
Male.setBounds(110,20,100,20);
Female.setBounds(210,20,100,20);
button.setBounds(50,50,80,15);


button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if((Male.isSelected()==false)&&(Female.isSelected()==false)){
JOptionPane.showMessageDialog(null,"Please select radio button");
}
}
});
f.add(lab);
f.add(Male);
f.add(Female);
f.add(button);

f.setSize(350,120);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

February 11, 2012 at 3:10 PM

Javascript radiobutton validation:

<html>
<script language = JavaScript>
function validate(){
   if ( ( document.f1.radios[0].checked == false ) && ( document.f1.radios[1].checked == false ) ){
        alert ( "Please choose Radio Button!" );
        document.f1.radios[0].focus();
        return false;
    }
return true;
}
</script>
<form name="f1" onsubmit ="return validate();">
<pre>
Select Gender: <input type="radio" name="radios" value="male">Male 
               <input type="radio" name="radios" value="Female">Female

<input name="Submit" value="Send" type="submit" >
</pre>
</form>
</html>

February 13, 2012 at 4:59 PM

Thanks for your reply









Related Tutorials/Questions & Answers:
validation of radio button
validation of radio button  There are 3 radio button as A,B,W. there are another radio as 1,2,3.if we select W in first radio button then should select 2nd one(1,2,3).if we select A or B not need select any one from 1,2,3
Radio button Validation
Radio button Validation  Hi.. How to validate radio button in java?if the radio button is not selected an error message should be given... Please...()==false)){ JOptionPane.showMessageDialog(null,"Please select radio button
Advertisements
Radio button validation using jsp - JSP-Servlet
Radio button validation using jsp  I had one jsp Page and servlet. I did my validations in servlet for my jsp page which contains the radio... a value for radio Buttons) then it will return to same jsp page with the given
radio button
radio button  On selecting a radio button, it should open a aspx page
I'm using struts2,i'm asking about the radio button validation <s:radio>
I'm using struts2,i'm asking about the radio button validation    i used this javascript code but it didnt work function valider(){ frm=document.forms['frmSaisie']; if(frm.elements['Gender'].value
I'm using struts2,i'm asking about the radio button validation <s:radio>
I'm using struts2,i'm asking about the radio button validation   my form < s: form action="creatingcv" method="post" onsubmit="return valider()" id="frmSaisie"> < s:radio name="cv.gender" label="Gender" list="{'Male
Struts 2 Radio Button
radio buttons and I am using Struts2 tag.I want first rado button to be selected by default.But when i select the second radio button and hit on search button i want to retain the selection of that second radio button on search list
radio button - Development process
radio button  hi, there is 2 radio button and five text box... but when i click on cr radio button and enter value in text box.it enter the msg but it again go to sr radio button   Hi friend, Plz give full
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
java radio button and exception
java radio button and exception  Dear Sir/Madam, I have problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1 radio button can be selected, but somehow 2 can be selected the same time. Also, I
iPhone Radio Button Example
iPhone Radio Button Example  Can you please suggest me how to create Radio button in my iPhone application. Actually, in my application i have two... click on that button it get selected and by default it should display unselected
Query on radio button
Query on radio button  I am having a multiple row in jsp page.They are dynamically coming. For each row there is one radio button. I want to select one row only, i.e I want to fetch the value of row and on submitting the page
dependent radio button
of the Radio Button is to select only one option at a time. So you don't need...dependent radio button  Hi. I have 4 radio buttons say all,chocolate,cookie,icecream. If I select all the other 3 should not able to be selected
passing value of radio button
passing value of radio button  hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second
radio button - Development process
radio button  hello,i want to creat two radio button.out of which only one can be selected.and can show the contain of selected radio box   Hi friend, Code to solve the problem : My Page Radio 11
access into radio button
access into radio button  access the four fields of database called access,access file and stored in radio button.please help
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button... radio button values from jsp to action using javascript
Radio button in JSP - JSP-Servlet
Radio button in JSP  Hi! In my page I have two radio buttons. If i select first radio button. one text field has to be displayed.... If i select second radio button. text field has to be disappeared. pls.... help me.. 
Using radio button in struts - Struts
Using radio button in struts  Hello to all , I have a big problem... options to choose : Serial number 12345 radio button - selection 1 radio button - selection 2 Serial number 6789 radio button - selection 1 radio button
to get radio button value - Struts
to get radio button value   hello friend, i have a problem regarding... two major problems:- 1.these radio button is not going to select also 2.i want to set the "value" attribute of radio button in the above code. Can u help
Radio Button in HTML
Radio Button in HTML is a type of input form that allows a user to select one button from a group of button. When a user clicks on a radio button, it becomes...; specifies the component type is radio button or not. If a programmer use type="radio
Dojo Radio Button
Dojo Radio Button         .... For creating radio button you need "dijit.form.CheckBox". The radio button do some action on press.  Try Online: Radio ButtonADS_TO_REPLACE_1
radio button in jsp - JSP-Servlet
radio button in jsp  hye there.how do I create radio button in jsp?Could you please gimme an example of shopping cart in jsp which have I have using a Netbean not a tomcat.What is the code for view and update in jsp?Thanks
Radio Button in Java
Radio Button in Java       Radio Button is a circular button on web page that can be selected by the user. The AWT  Widget used to create a radio button is Checkbox
On selecting a radio button, it should open a jsp page.
On selecting a radio button, it should open a jsp page.  Hi, COuld you please tell me how to link a radio button selection to a jsp. My requirement is if I select a radio button then it should open a jsp page. thank you
pass radio button values to next page
pass radio button values to next page  how to pass selected radio button values which coming from mysql database to next page using php. Please show me with examples
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
radio button value on edit action
radio button value on edit action  This is my edit.jsp code...In my......Problem 'm facing is on edit action 'm not retrieving radio button value..i have used if else logic..Bt its not working...My edit.jsp code is:-Radio button name
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... database and according to that i want to check the cash cheque radio button... information from database the i want to show cash radio button checked.How can i do
JQuery-check/uncheck radio button in jQuery
JQuery-check/uncheck radio button in jQuery  Hi Sir, I want to know how can i check/uncheck input or radio button?   You can check/uncheck radio button by setting the 'checked' attribute to true or false as follows
Struts 2 radio button value problem
Struts 2 radio button value problem  When I use s:radio tag in struts 2, I'm not able to get the selected value using document.getElementById... gives first radio option's value as the value for any option selected. Ex
display contents on the same page by selecting a radio button
on the same page under the radio button...display contents on the same page by selecting a radio button  Bill...;input type="radio" name="bill_status " value="due" /> Received<
Get radio button value after submiting page
Get radio button value after submiting page  Radio buttons are dynamically generated.After selecting radio button & submitting the page , the value of the selected radio button get displayed in that jsp page. <
Drop down and radio button value on edit action
Drop down and radio button value on edit action  HI, I have... the value from dropdown and radio button.. But the problem goes with edit action... for text boxes..bt select default value for dropdown and radio button...How do
JSP Radio Button MySQL insert - JSP-Servlet
JSP Radio Button MySQL insert  Hi, I have an HTML form which has a couple of radio buttons for example (gender: male/female) and some check boxes... with the code to store radio button data and checkbox data to MySQL table. For example
get a radio button click value - JSP-Servlet
get a radio button click value  thanks sir for sending code ,but i...") in servlet that is used in another jsp so can i call getParameter("radio") i.e in the input tag name="radio" eventhough i m getting a null value please help me
Radio button with values from a String ArrayList in JSP?
Radio button with values from a String ArrayList in JSP?  Radio button values in JSP ArrayList<String> cs = CourseAssignments.getInstance... input. I want to display a radio button near each course, then user selects one
Radio Button in J2ME
Radio Button in J2ME      ... to demonstrate, how to create the radio button in J2ME using MIDlet. The radio button is use to choose only one option at a time. To create the radio button we
radio button selection should move the control to a text box that needs to be complete
radio button selection should move the control to a text box that needs to be complete  on selection of a radio button mouse should move to a particular text box that needs to be filled. How
Radio Button In Java
Radio Button In Java       Introduction In this section, you will learn how to create Radio Button... In this program a radio button is created that is an item that can be selected
Write a program to design a page.use radio button?
Write a program to design a page.use radio button?  i would lik..."); radioGroup.add(Female); JButton button=new JButton("Submit"); lbl1.setBounds(50,50,70,20...); f.add(button); f.setSize(500,500); f.setVisible(true); f.setDefaultCloseOperation
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem. i have a system to input data from a jform to a mysql database. i have made... is clicked depending on which button was clicked male or female be sent
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem. i have a system to input data from a jform to a mysql database. i have made... is clicked depending on which button was clicked male or female be sent
how to display default radio button in struts2.0 for first time login - Struts
how to display default radio button in struts2.0 for first time login  hi, this is suresh jampala, i have one question regarding struts2.0,how can i display default radio button in struts2.0 when ever i loggedin first time
getting radio button at start of each row of table - Struts
getting radio button at start of each row of table  i have done the following things, and this is fine for me. But i want radio button at the place.... USERNAMESKILL (at this place i want radio button
Selecting a radio button in jquery autocomplete from database value
Selecting a radio button in jquery autocomplete from database value  ... radio button? Here is the pertinent code: $("#name").autocomplete... to do is to select the appropriate radio button. Any pointers please
com.vaadin - vaadin-radio-button-flow version 14.10.1 Maven dependency. How to use vaadin-radio-button-flow version 14.10.1 in pom.xml?
com.vaadin  - Version 14.10.1 of vaadin-radio-button-flow Maven dependency? How to use  com.vaadin  - Version 14.10.1 of vaadin-radio-button-flow in pom.xml? How to use vaadin-radio-button-flow version 14.10.1 in pom.xml
com.vaadin - vaadin-radio-button-flow version 22.2.0 Maven dependency. How to use vaadin-radio-button-flow version 22.2.0 in pom.xml?
com.vaadin  - Version 22.2.0 of vaadin-radio-button-flow Maven dependency? How to use  com.vaadin  - Version 22.2.0 of vaadin-radio-button-flow in pom.xml? How to use vaadin-radio-button-flow version 22.2.0 in pom.xml
How to use radio button in jsp page
How to use radio button in jsp page       This is detailed java code how to use radio button in jsp code and display a message in another jsp page according
when radio button is selected corresponding jsp page should open
when radio button is selected corresponding jsp page should open  how to write code in HTML & jsp, when we click on radio buttons...="form"> View Profile<input type="radio" value="view" name="radios" onclick

Ads