wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes JSP and radio buttons passing values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JSP and radio buttons passing values" Watch "JSP and radio buttons passing values" New topic
Author

JSP and radio buttons passing values

Susan Crystal
Greenhorn

Joined: Dec 06, 2004
Posts: 5
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

You will need to load the bottom page using Javascript. Movig this along to the HTML/Javascript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Basic idea:



Eric
Susan Crystal
Greenhorn

Joined: Dec 06, 2004
Posts: 5
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Dec 06, 2004
Posts: 5
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP and radio buttons passing values
 
Similar Threads
Enable-Diable Radio Buttons
radio buttons and buttons
Storing the value of a radio button
servlets/jsp
Radio Buttons