• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP and radio buttons passing values

 
Susan Crystal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok read through many post here about radio buttons and jsp. Some come close to answering question, but not close enough.

I have a webpage that has 2 frames, and in those to frames are seperate jsp. The top is the header, which has nice picture and a row of four radio buttons.

<td>
<input type="radio" value="today" name="timeFrame" checked/><b>Today</b>
<input type="radio" value="week" name="timeFrame"/><b>7 Days<b>
<input type="radio" value="month" name="timeFrame"/><b>30 Days<b>
<input type="radio" value="all" name="timeFrame"/><b>All Days<b>
</td>

The bottom frame has jsp that displayes info. According to time span. Example last 7 day, last 30 days , today, and all days.

Now my problem is I need to make it so the radio buttons on the first jsp page at top frame are connected somehow to the 2nd jsp at bottom so that when a user clicks on one of the radio buttons at top the bottom jsp responds by showing the approprate page.

I do not know how to pass the value of the radio button that is chosen to the 2nd jsp page?

The 2nd page has the <@ code in it to diplay the appropriate page. I just dont get how to tell the 2nd jsp page what radio button on the 1st jsp page is choosen.

Any help much appreciated.

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to load the bottom page using Javascript. Movig this along to the HTML/Javascript forum.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic idea:



Eric
 
Susan Crystal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for reply...

I am not certain i understand what you have shown me. I dont see how the value(for example in my code "today") gets passed to a java method in a jsp.

I am not certain why my post was moved ...my question was about jsp, java not javascript. I do know the difference.

I need to pass the value of variable from the radio button depending on which is clicked. It needs to be passed to a method inside the JSP number 2 which is deplayed inside frame 2, hince java not javascript.

If using javascript is way to go then fine no problem with using it. It is just that the java method i want to pass variable to does some date stuff and database looking up. Kinda complicated and did not want to have to mess with it, just hand it the variable and run

any help appreciated

thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to get the data to that frame somehow. This is just pasing data from the client to the server. Hence why it was moved to this forum.

You can use the method I shown with a query string. That will allow you to access it wih your server side code.

If that does not work, then you need to submit the form in the top frame. In order to do that, you can set the target attribute with the frame name.

Those are the two ways to do it.

Eric
 
Susan Crystal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Humm...

I came across the target=mainFrame thing for instance but I dont see what code actullay passes the variable to the method inside 2nd jsp?

The method name i am calling wich is java code not javascript is called display().

simple by the user selecting the radio button. Does that pass the value "today" to the java method display()? hince java not javascript

I tried this but the jsp2 is oblivious to that it has been passed anything.

thanks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frames act like seperate windows, your Java Code can not talk between them. The only way that you are going to get data from the client side (radio buttons) to the server side (your function display()) is by submitting a form or a querystring.

On your Java code you need to look at the querystring or the form submission parameters that are passed to the server. With that data you should be able to get the value "today" which you are after.

The JavaScript code is just giving you the ability to submit the form or create a querystring so the user does not have to click a button.

With JavaScript, you can submit the form with document.formName.submit();

you can add it to the onclick event like onclick="document.formName.submit();"

So now when the user selects a radio button the form in the top frame is submitted and you place the target to your other frame. That frame can then grab the value from the form submission.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic