*
The moose likes Servlets and the fly likes java check box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "java check box" Watch "java check box" New topic
Author

java check box

D Bit
Greenhorn

Joined: Apr 12, 2004
Posts: 2
if the check box is checked then update this table in sql with 'Y'

and if its not checked its false then the table will be updated with 'N'

im just not sure how to make the check box tell the variable if its true or false
can ya help me out how would i tackle this
thanks

//jumpball project

boolean jumpBall = false;


out.println("<TD COLSPAN=1>Jump Ball<INPUT TYPE=CHECKBOX NAME=JumpBall VALUE=JumpBall onfiltered=></TD>");


Statement appStat = con.createStatement();

if(JumpBall == true)

{


ResultSet appRS = appStat.executeQuery("update "Constants.DATA_LIB +

".desgnfrcst set JUMPBALL = 'Y' where DESIGN_NUMBER=" DesCode);

}

else

{

ResultSet appRS = appStat.executeQuery("update "Constants.DATA_LIB +

".desgnfrcst set JUMPBALL = 'N' where DESIGN_NUMBER=" DesCode);

}
Raja Sagar Panamgipalli
Ranch Hand

Joined: Aug 13, 2003
Posts: 109
Hi Pal ,
Here is a hint
this can be done easily with a Hidden variable and in JSP.

Inside JSP page u can use Html tags.
Inside the Javascript Just change the value of hidden variable to that of which ever the checkbox user checks..and set the form action to POST ..so when ever the the page is posted ..the value of the check box is copied into the hidden variable..and using request.getParameter('HiddenVariable')you can access it and u can post it inside the database.

Give two check boxes with values Y and N ..whenever any one of them is checked...pass this value to the hidden variable....

I think u should be using a radio button for this purpose..as the user has to say either a 'Yes' or a 'No' he cannot say both...


good luck..Pal..


SCJP 1.4<br />SCBCD 1.3
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
As this is in the Servlets forum I will give an answer relative to Servlets.

In your HTML you will have something like <input type="checkbox" name="widget1" />

In your Servlet do the following..
boolean jumpball = (request.getParameter("widget1") != null);

If the checkbox is checked, a parameter with the name of widget1 (value is not needed) will be available, thus not equal to null. If the checkbox is not checked there will not be a parameter with the name of widget1, or equals to null.

One line of code on the servlet side handles this without having to change the checkbox.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Copying the value of the checkbox to a hidden element is a useless exercise. Ken's suggestion is a much more straight-forward means of approaching the issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java check box