• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

select element as parameter for query

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have 3 select boxes on my jsp page box1=region, box2=country based on selection in box1 and box3=what is in database based on selection in box1. My question is, is there a way to grab the selection from box1 and put it into the where clause of a sql statement???
Thanks!
[ February 23, 2005: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the form is submitted the value of the select element is sent as a request parameter just like any other. Are you having a specific issue?
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to have to re-post the page if at all possible. I just want to be able to read what is selected in the first box and take that selection and plug it into the where clause of my sql query to the database to populate the 3rd box. Is this doable?
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely you can populate select box without rePOSTing, but it is non trivial task.

you must do the following things but I will not describe details.
Actually, I want to scare you out of such kind a solution.

1. create separate page, which create output based on parameter in box1
Query the database, get ResultSet, and dynamycally write output like
following.
let it be /box3pop.jsp?param=x, where x is value of select box1

<html>
<head>
<script type="text/javascript">
window.on load = function () {
parent.document.getElementById('idbox3').innerHTML=document.body.innerHTML
}
</script>
</head>
<body> <!--output is based on a value of x-->
<option value="22">sdscd</option>
<option value="44">ttyy</option>
<option value="91">zzzzzz</option>
</body>
<html>


2. insert hidden iframe in your form.

<select onchange="populateBox3(this)" name="box1">
<option>sds</option>
......
</select>
.......
<select id="idbox3" name="box3">
<option></option>
</select>

<iframe name="hidFrame" style="display:none"></iframe>

3. insert javascript in page your page original, first page

function populateBox3(selectBox1) {
var hiddenFrame = document.frames['hidFrame'];
hiddenFrame.src='/box3pop.jsp?param=' + selectBox1.value;
}


.....
Cool, heh?
Regards
[ February 23, 2005: Message edited by: Eugene Lucash ]
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eugene! But I think I am going to go with a preparedStatement if I can only get it to read the selection in the select box
 
Eugene Lucash
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at another solution, but with postbacks
https://coderanch.com/t/115659/HTML-JavaScript/Select-Box-one-page-second

post #6
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am I forced to do post back? Won't this work?

 
Eugene Lucash
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main difference is in what you want.
If you want box1 and box3 on the same page,
so than box3 populated dependantly on box1 value
you need postback or some javascript stuff
(including separate hidden server request) to repopulate box3.

If you can place box1 on one page,and after submiting
you respond with the second page where box3 placed (in a wizard maner)
then you don't need any extra stuff.
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I want both on the same page. I already have an onchange event for box2, I guess I will also have to write one for box3. Thanks for your time.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you might not have a full grasp on what gets executed on the server and what gets executed on the client.

Onchange events happen on the client (the users browser). The only way to use the values in a select box for your JDBC statement is to post the information back to the server.
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic