We help IT Professionals succeed at work.

Using Two Frames, Capture the value of a <select> option and set it to a variable

jollykh
jollykh asked
on
Medium Priority
166 Views
Last Modified: 2010-04-01
Hello Experts,

I have an JSP page with two frames.  Upon a submit, I want to capture the value of one of my frames(frame1) and set it to a variable (i.e. Java variable) in my other frame (frame2).  For example,

frame1:
<form name="test">
<select name="count">
  <option value="0">0</option>
  <option value="5">5</option>
  <option value="10">10</option>
</select>
<input type=submit>
</form>

frame2

//get the value from "count"
int mycount = count;

How can this be done?  I tried setting a hidden variable in frame2 and setting it from frame1 upon a submit, but that didn't seem to work.
Ex:

frame1:

//Javascript
 parent.positions.document.forms[''].elements['mytest'].value=
              document.forms[0].elements['count'].options[
                  document.forms[0].elements['count'].selectedIndex
              ].value;    

frame2:

 <input type="hidden" name="mytest" value=""> //can I somehow extract this value in my page and set it to a variable?

Thank you for your help!
Comment
Watch Question

Commented:
Let me clarify.

1)You want to set the hidden parameter of frame2 when the frame1 is submitted?? Is it?

2)Or you want to take a value from frame 2 and set the value in frame1 ?

2nd option is quite possible. The first option is not.

regards,
fargo

Author

Commented:
Hello Fargo,

I'm looking at option 1.  This is possible through javascript (see the snippet of code in my originial question).  My question is once I <b>set</b> the value, can I <b>get</b> the value in the JSP?

Thanks!
CERTIFIED EXPERT
Top Expert 2004

Commented:
you could have a third hidden frame which posts the value to frame 2 before posing this form to frame 1

Tim

Author

Commented:
I have come to discover that the only was I can get this accomplished is by calling the request.getParameter from my java class and setting the variable to the session.

Thanks everyone for your help!
CERTIFIED EXPERT
Top Expert 2004

Commented:
ok by me
Commented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.