Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

select element as parameter for query

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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 ]
 
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!