aspose file tools*
The moose likes JSP and the fly likes Comparing value of radio button against answer from the  database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Comparing value of radio button against answer from the  database" Watch "Comparing value of radio button against answer from the  database" New topic
Author

Comparing value of radio button against answer from the database

Anudeep Pat
Greenhorn

Joined: Apr 09, 2010
Posts: 10
Hi,

I am a novice and am trying to create a login page. The flow is:

1.User enters username and password.

2. He is then asked a question from database which has radio buttons

3. The selected value should be checked against a radio button selected to allow the user to login.

The login part is ok, have a problem getting the answer for the question, also the answer which I took as the hidden value is displayed

Code for Question.jsp


And the code for Welcome.jsp


I am exhausted searching for the errors, can someone please help me!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

As a novice, it's important to not learn bad habits from the start: begin with removing all Java code from JSP pages. Java should be performed in servlet controllers and beans and has no place in a modern JSP.

Also, the use of all uppercase for HTML is a really old-fashioned convention that makes your code very hard to read. Use lowercase and it'll look a lot better.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anudeep Pat
Greenhorn

Joined: Apr 09, 2010
Posts: 10
OK, thanks for the advice,

Removed the capitalization, but cannot move the javacode out of the JSP right now, so please give it a look!

Have a deadline to meet.
Anudeep Pat
Greenhorn

Joined: Apr 09, 2010
Posts: 10
Can some one please help!
praneel shah
Greenhorn

Joined: Mar 16, 2010
Posts: 17
first find the value of radio button with the code below and then compare it wid database....

<script language="JavaScript">

function getRadioValue() {
for (index=0; index < document.frmRadio.choice.length; index++) {
if (document.frmRadio.choice[index].checked) {
var radioValue = document.frmRadio.choice[index].value;
break;
}
}
}

</script>
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Anudeep Pat wrote:OK, thanks for the advice,

Removed the capitalization, but cannot move the javacode out of the JSP right now, so please give it a look!

Have a deadline to meet.


Why not? It should be done the first thing to avoid further problems.

By the way you didn't tell us what your problem is.

Is Question.jsp compiling? This line seems not to be correct (well, this and all the inputs)
Anudeep Pat
Greenhorn

Joined: Apr 09, 2010
Posts: 10
Everything is compiling but I guess there's a problem comparing the value of the radiobutton selected to the hidden value am sending in the answer field
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18165
    
    8

Anudeep Pat wrote:I guess there's a problem comparing the value of the radiobutton selected to the hidden value am sending in the answer field

But guessing is not a very practical problem-solving method.

First of all here's what you should do to compare the value returned from the radio button against the answer from the database:
  • Get the value from the radio button into a variable
  • Get the value from the database into another variable
  • Compare the two values


  • If that doesn't work the way you think it should, then perhaps you're getting an unexpected value from the radio button. Or from the database. Don't guess, or assume, what is happening then. Display both values and see what you are dealing with. It's called "debugging".
    adil qureshi
    Ranch Hand

    Joined: Jul 11, 2008
    Posts: 48
    See when you are actually submitting the form all the values are sent so will give you only the first value because its actaualy an array , try to take a print of this value ,what i suggest that instead of using submit use a normal button and onclick of that call your own function that will submit the form, here write java script code that only sends the selected value .And i dont think theres any problem with the answer field you will be getting that surely.

    SCJP 1.5,SCWCD 1.5
    Anudeep Pat
    Greenhorn

    Joined: Apr 09, 2010
    Posts: 10
    thanks a lot for the help!!

    Hope it'll work!
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Comparing value of radio button against answer from the database
     
    Similar Threads
    About create a session!
    How to store option format value in database in jsp
    Why am i getting NullPointerException but runs properly
    Login JSP page using mysql(DB)
    How to insert arabic letters in MySql through jsp