Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

simple radio button question

  • 12-11-2005 07:27AM
    #1
    Registered Users, Registered Users 2 Posts: 868 ✭✭✭


    Hi,

    Java code problem - my servlet needs to check if a group radio button (submitted on a HTML form) has been selected or not.

    In other words - if the submit is clicked and none of the radio button options has been selected, what is the Java code to check?

    Make any sense?

    D.


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    if(!Button1.IsSelected && !Button2.IsSelected && !Button3.IsSelected)
    {
    Do Code for when nothing is selected
    }

    of course, syntax might be different for java, but the idea would be the same.


  • Closed Accounts Posts: 324 ✭✭madramor


    if(!Button1.IsSelected && !Button2.IsSelected && !Button3.IsSelected)
    {
    Do Code for when nothing is selected
    }

    of course, syntax might be different for java, but the idea would be the same.
    servlets are serverside components they only interact with
    the client using the HTTP protocol so the above will not work
    <FORM action="doit">
       <INPUT TYPE="RADIO" NAME="anything" VALUE="1">One</INPUT>
       <INPUT TYPE="RADIO" NAME="anything" VALUE="2">Two</INPUT>
       <INPUT TYPE="RADIO" NAME="anything" VALUE="3">Three</INPUT>
       <INPUT type="submit" value="doit">
    </FORM>
    
    String val = request.getParameter("anything");
    if(val == null)
       out.println("no buttons ticked");
    else
       out.println("Checked was: "+val);
       // will give 1 || 2 || 3
    


Advertisement