• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing value of radio button against answer from the database

 
Anudeep Pat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anudeep Pat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one please help!
 
praneel shah
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 48
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Anudeep Pat
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks a lot for the help!!

    Hope it'll work!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic