[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Java (Select Box) OnChange - Not JavaScript

Posted on 2009-05-14
25
Medium Priority
?
743 Views
Last Modified: 2013-12-07
I need to able to retrieve some values and place them in another select box(parameter_pool_time)
basically when you choose from the select box session type i want it to do a onchange and get me the values in SQL Database i have linked

I am totally clueless as to where to start, please help me i really need this.

i have done this in C# and Access Database before but this is totally different i have no clue how id do it in Java. please help me i have really less time left.

PS: Remember Java not JavaScript.
out.println("<TR><TH>Session Type</TH><TH>Day</TH><TH>Click Button to get times</TH></TR><TR><TD><select name=\"parameter_pool_sessiontype\"><option value=\"Members Swimming\">Members Swimming</option><option value=\"Aqua Aerobic\">Aqua Aerobic</option><option value=\"Adults Only\">Adults Only</option><option value=\"Aqua Deep End Swim\">Aqua Deep End Swim</option><option value=\"Splash Time\">Splash Time</option></select></TD>");

Open in new window

0
Comment
Question by:WarAngelos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 11
25 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24387927
You need to activate a form submission via javascript that performs the *java* at the server side
0
 

Author Comment

by:WarAngelos
ID: 24387995
roughly how do i do that?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24388198
Which bit, the javascript or the java?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:WarAngelos
ID: 24388227
the javascript bit please
0
 

Author Comment

by:WarAngelos
ID: 24388392
If this helps this is the whole thing i have

this is incomplete i am using it form another of my pages and working top to down i have not really reached the try/catch part yet I am stuck on how to do onchange.
package dh101;
 
 
 
import java.io.*;
 
import java.util.*;
 
import java.sql.*;
 
 
 
import javax.servlet.*;
 
import javax.servlet.http.*;
 
 
 
 
 
public class Pool extends HttpServlet
 
{ 
 
    public void doGet (
 
			HttpServletRequest	request,
 
			HttpServletResponse	response
 
		) throws ServletException, IOException
 
		{
 
 
 
		PrintWriter	out;
 
		String Title = "Pool Bookings";
 
		String parameter = "";
 
		String pool_username = "";
		String pool_time = "";
		String pool_day = "";
		String pool_sessiontype = "";
 
		String sql = "";
 
		Connection dbcon = null;
 
		Statement stmt = null;
 
		ResultSet rs = null;
 
 
 
		if( (parameter = request.getParameter("parameter_pool_time")) != null) 
 
		  pool_time  = parameter;
 
		if( (parameter = request.getParameter("parameter_pool_day")) != null) 
 
		  pool_day  = parameter;
		if( (parameter = request.getParameter("parameter_pool_sessiontype")) != null) 
 
		  pool_sessiontype = parameter;
 
 
 
 		// set content type 
 
		response.setContentType("text/html");
 
		// then write the data of the response
 
		out = response.getWriter();
 
		out.println("<HTML><HEAD><TITLE>" + Title + "</TITLE></HEAD>");
 
		out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"dh101.css\" />");
		out.println("<BODY><CENTER><H1>" + Title + "</H1>");
 
		out.println("<img height=450 width=700 src=\"images/pool.jpg\">");
 
		out.println("<H3>Pool Booking Form</H3>");
 
		out.println("<form>");
		out.println("<TABLE>");
		out.println("<TR><TH>Personal Details</TH></TR>");
 
		out.println("<TR><TH>Session Type</TH><TH>Day</TH><TH>Click Button to get times</TH></TR><TR><TD><select name=\"parameter_pool_sessiontype\" onchange=\"function()\"><option value=\"Select\">Select</option><option value=\"Members Swimming\">Members Swimming</option><option value=\"Aqua Aerobic\">Aqua Aerobic</option><option value=\"Adults Only\">Adults Only</option><option value=\"Aqua Deep End Swim\">Aqua Deep End Swim</option><option value=\"Splash Time\">Splash Time</option></select></TD>");
 
		out.println("<TD><select name=\"parameter_pool_day\"><option value=\"Select\">Select</option><option value=\"Monday\">Monday</option><option value=\"Tuesday\">Tuesday</option><option value=\"Wednesday\">Wednesday</option><opjavation value=\"Thursday\">Thursday</option><option value=\"Friday\">Friday</option><option value=\"Saturday\">Saturday</option><option value=\"Sunday\">Sunday</option></select></TD>");
		out.println("<TR><TH></BR>Booking Details</TH></TR>");
 
		out.println("<TR><TH>Time</TH><TR><TD><select name=\"parameter_pool_time\"><option value=\"B\">B</option></select></TD>");
 
		out.println("</TR></TABLE></BR>");
		out.println("<input type=submit>");
 
		out.println("</form>");
 
		try 
 
		{
 
			// Load the JDBC-ODBC driver
 
			Class.forName("com.mysql.jdbc.Driver").newInstance();	
 
			dbcon = DriverManager.getConnection("jdbc:mysql://localhost/test");
 
			stmt = dbcon.createStatement();
 
			//insert data into event database table
 
			if(!pool_username.equals("") && !pool_time.equals("") && !pool_day.equals("") && !pool_sessiontype.equals("") )
 
			{
 
				//sql = "INSERT INTO pool VALUES ('" + pool_firstname + "','" + pool_lastname + "','" + pool_start + "','" + pool_end + "','" + pool_date + "','" + pool_sessiontype + "')";
 
				// Load the JDBC-ODBC driver and execute SQL statement
 
				//stmt.executeUpdate(sql);
 
			}
 
			
 
			//read data from database table
 
			rs = stmt.executeQuery("SELECT * FROM pool");
 
			out.println("<TABLE BORDER=1>" );		
 
			out.println("<TR><TH>First Name</TH><TH>Last Name</TH><TH>Start Time</TH><TH>End Time</TH><TH>Date</TH><TH>Session Type</TH></TR>" );		
 
			while ( rs.next() )
 
			{
 
				/*out.println("<TR><TD>" +  rs.getString("pool_firstname") + "</TD>" );
				out.println("<TD>" +  rs.getString("pool_lastname") + "</TD>" );
 
				out.println("<TD>" +  rs.getString("pool_start") + "</TD>" );
 
				out.println("<TD>" +  rs.getString("pool_end").toString() + "</TD>" );
				out.println("<TD>" +  rs.getString("pool_date") + "</TD>" );
				out.println("<TD>" +  rs.getString("pool_sessiontype") + "</TD>" );*/
 
			}
 
			out.println("</TR></TABLE>" );				
 
			stmt.close();
 
			dbcon.close();
 
		}		
 
		 catch( Exception e ) 
 
		{ 
 
            e.printStackTrace(out);
 
 
 
		}//catch	
 
		out.println("</BODY></HTML>");
 
		out.close();
 
			
 
  }
 
}
 
//end/////////////////////////////////////////////////////////////////////////////////////////////////////////

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24388726
Are you sure about this onchange thing? I would advise against it and make them click explictly or you'll find that you'll be handling more queries than you (or they) need
0
 

Author Comment

by:WarAngelos
ID: 24388855
Please i have no other choice i have a TEST 2morrow Network Software then i have to work Friday Night Shift and Saturday Night Shift Sunday University is closed library does not have linux and Monday i need to Hand this in am totally paniking right now.
0
 

Author Comment

by:WarAngelos
ID: 24388880
Basically what i want is if your look at the code there are 3 Select Boxes... 2 of them are preloaded... when they are selected i want it to do the onchange thing then check compare the two value is the thing and get the times and put them in the 3rd select box.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389075
OK. Here's an onchange example

http://www.java2s.com/Code/JavaScriptReference/Event-Handlers-Reference/onChangeExample.htm

In your case, all you need in 'function1' is
document.forms[0].submit();

Open in new window

0
 

Author Comment

by:WarAngelos
ID: 24389123
but how would i connect it to the sql i am really sorry for being a pain... basically i have sql totally figure out in java but in javascript i have not got a clue how to access it and stuff
0
 

Author Comment

by:WarAngelos
ID: 24389141
nvm thank you soo much i deffinetly owe you one... i have got it man thanks
0
 

Author Comment

by:WarAngelos
ID: 24389156
Just one more thing once i get to sql how to i replace the stuff in select box i know whats going on now its submiting hence activating the try and catch but in there i know how to retrieve the details but how to do add it to the SELECT BOX just this one please tell me thank you.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389168
That's it. It's the java side that does the SQL - nothing to do with the javascript. JS just submits the form
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389193
>>Just one more thing once i get to sql how to i replace the stuff in select box

Well i don't know what your application logic is but basically all you do is rewrite the html (and hence the select element) based on what the query returns
0
 

Author Comment

by:WarAngelos
ID: 24389266
Hmm sorry but err right for e.g. when i say choose members swimming and monday

sooo in sql i would be like SELECT SESSION, DAY, TIME FROM SWIMMING WHERE SESSION = '"+SELECTBOX1+"'" and the other select box...

write so it gets me the stuff but it would not change the 3rd select box on its own thats for sure i need the code to put these results into the SELECT BOX.
I dunno how to add not even a clue on how to start

I hope you get me.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389328
You need to iterate the ResultSet and get the values you need from which you can rewrite the html. What purpose to your app does the third select serve?
0
 

Author Comment

by:WarAngelos
ID: 24389375
basically this is pool booking site...

its not a app....its a webpage

Session Type(SELECT BOX 1) and DAY(SELECT BOX 2)

With them I want the time for these two togeather for e.g. session members swimming and day monday
with these two i would like the time of session members swimming available on monday
and insert these times into TIME(SELECTBOX 3) soo the user may choose the time and then place a booking.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389426
OK, so what you should do is iterate the ResultSet and get the times and put them in the 3rd select. By 'app' i mean of course 'webapp', however it happens to be deployed
0
 

Author Comment

by:WarAngelos
ID: 24389488
yeah that is what i want to do i no how to use resultset but how do i insert these values into the 3rd select thats the question i have sorry for being a pain... i appreciate that you have not ditched me so far or i would have thought some one else would have left me ages back LOL
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 24389603
Your code should look something like this:
out.println("<TR><TH>Time</TH><TR><TD><select name=\"parameter_pool_time\">");
while (rs.next()) {
	String time = rs.getString("time");
	out.println("<option value=\"" + time + "\">" time + "</option>";
}
 
out.println("</select></TD>");

Open in new window

0
 

Author Comment

by:WarAngelos
ID: 24389631
Will this add even if the there are multiple members swimming sessions basically multiple times more than 1? thank you so much ^^
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389667
It will loop through any and all times present in the ResultSet
0
 

Author Comment

by:WarAngelos
ID: 24389770
Okay Thank you very much for you help i really appreciate it... I have to leave campus now the build is closing only library's stay open 24/7.. thank you again.

Ill give the code a go thank you very much.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24389804
OK :-)
0
 

Author Closing Comment

by:WarAngelos
ID: 31581605
Thanks a lot you were really helpful thank you.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video teaches viewers about errors in exception handling.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question