| | |
2 comboboxes values of 2nd depends on 1st ,OPTION values from Database
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Once you decide to follow MVC standard, you can contact me.
Secondly you should start learning about basic deployment with Tomcat
Secondly you should start learning about basic deployment with Tomcat
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Jun 2009
Posts: 22
Reputation:
Solved Threads: 1
the best answer is ajax and actually you do not to learn ajax just copy
the code i will gave and follow the guidlines copy and paste the attached file into your project folder :
1- copy and paste the attached file into your project folder
2- copy the following code and paste into the head of you jsp file
3- in your itemname combobox html make it exactly like follow
4- copy and paste the following code where do you want the itemcode to be appeare
5- now you just need to open new jsp file and copy write the following
5- i wish it will help ,
the code i will gave and follow the guidlines copy and paste the attached file into your project folder :
1- copy and paste the attached file into your project folder
2- copy the following code and paste into the head of you jsp file
<script type="text/javascript" src="prototype.js"></script> <script> function item_code1(value){ var myAjax1=new Ajax.Request('itemcode1.jsp',{ method: 'post',postBody:'id='+value, onSuccess: function(transport) { var itemcode1=$('itemcode1'); itemcode1.update(transport.responseText); } }); }
3- in your itemname combobox html make it exactly like follow
<select name="itemname1" size="1" id="first1" onchange="item_code1($('first1').value);"> 4- copy and paste the following code where do you want the itemcode to be appeare
<div id="itemcode1"> </div> 5- now you just need to open new jsp file and copy write the following
jsp Syntax (Toggle Plain Text)
<%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <% String id=request.getParameter("id"); Vector v1,v2; [COLOR="Red"]jmm[/COLOR].Database database = new jmm.Database(pageContext.getServletContext().getRealPath("/WEB-INF/config.txt")); // depend on yours database.jdbcConnect(); String sql; sql = "select itemcode from item where itemname='"+id+"'"; out.print("<select name=itemcode1 id=\"itemcode \">"); v1=database.jdbcMultipleRowQuery(sql); if(v1.size()!=0){ for(int i=0;i<v1.size();i++){ v2 = (Vector)v1.elementAt(i); for(int j=0;j<v2.size();j++){ out.print("<option>"+v2.get(0)+"</option>"); } } out.print("</select>"); }else{ } database.jdbcConClose(); database = null; %>
5- i wish it will help ,
Last edited by peter_budo; Jun 29th, 2009 at 4:05 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
CoSIS1>the best answer is ajax and actually you do not to learn ajax just copy the code i will gave and follow the guidlines copy and paste the attached file into your project folder.
How did you know AJAX? just copy the code?
Wrap up source code with bb code tags.
Read
How to use BB code tags?
How did you know AJAX? just copy the code?
Wrap up source code with bb code tags.
Read
How to use BB code tags?
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 1
JSP Syntax (Toggle Plain Text)
<html> <head><title>Sales Page/title></head> <body> <script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { //alert("i m not in ready state"); if(xmlHttp.readyState==0) { //document.myForm.time.value=xmlHttp.responseText; alert("The request is not initialized"); } if(xmlHttp.readyState==1) { //document.myForm.time.value=xmlHttp.responseText; alert("The request has been set up"); } if(xmlHttp.readyState==2) { //document.myForm.time.value=xmlHttp.responseText; alert("The request has been sent"); } if(xmlHttp.readyState==3) { //document.myForm.time.value=xmlHttp.responseText; alert("The request is in process"); } if(xmlHttp.readyState==4) { //document.myForm.time.value=xmlHttp.responseText; //alert("i m in ready state"); document.getElementById("theResponse").innerHTML = xmlHttp.responseText; } } var itemname=document.myForm.itemname.value; var url="getProduct.jsp"; url=url+"?itemname="+itemname+"&sid="+Math.random(); //url=url+"&sid="+Math.random(); xmlHttp.open("GET",url,true); xmlHttp.send(null); } </script> select itemname: <form name="myForm"> /* wrong code------ <option>processors</option> <option>speakers</option> <option>monitor</option> <option>mouse</option> due to this code you can not get the value in the request.getParameter("itemname"); */ <!-- right code ---> <select name="itemname" onChange="ajaxFunction();"> <option value="processors">processors</option> <option value="speakers">speakers</option> <option value="monitor">monitor</option> <option value="mouse">mouse</option> </select> <div id="theResponse"> </div> </form></body> </html>
Now your second page getproduct.jsp
i have removed un necessary code
JSP Syntax (Toggle Plain Text)
<%@ page language="java" contentType="text/html" import="java.sql.*" %> <html> <head><title>select box demos</title></head> <body> <% try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=DriverManager.getConnection("jdbc:odbc:select"); try { String val=request.getParameter("itemname"); //String val1="speakers"; //String val2="processors"; // String itname[]={}; // int i=0,j=0,m=0; String str="select * from stocks where item_name=?"; PreparedStatement stmt=conn.prepareStatement(str); stmt.setString(1,val); ResultSet rs=stmt.executeQuery(); /* itname=new String[100]; while(rs.next()) { itname[m]=rs.getString(3); m++; } for(j=m;j<100;j++) { itname[j]="null"; } */ %> Prod Name: <select name="productname"> <% while(rs.next()) { // if(itname[i]!="null") out.println("<option value="+rs.getString(3)+">"+rs.getString(3)+"</option>"); //i++; } // out.println("</select>"); } catch(SQLException e) { out.print("SQL Not Executing"); } } catch(Exception e) { e.printStackTrace(); } finally { try { if(rs!=null) { rs.close(); rs=null; } if(stmt!=null) { stmt.close(); stmt=null; } if(conn!=null) { conn.close(); conn=null; } }catch(SQLException e) { out.print("SQL Not Executing"+e); } } %> </select> </body> </html>
![]() |
Similar Threads
- how to read form element values (JavaScript / DHTML / AJAX)
- checking if same values exist in the database and generating reports (VB.NET)
- Retaining textbox values (PHP)
- Get sum of values in a loop? (PHP)
- combobox selected value connected to a SQL statement (VB.NET)
- Retrieve values from sql server 2005 (ASP.NET)
- Reading an Access Database (VB.NET)
- question about php string function (PHP)
- unsigned character pointer to Hex values (C++)
- help with polymorphism and inheritance...getting null values (Java)
Other Threads in the JSP Forum
- Previous Thread: sending an email with pdf file everyday
- Next Thread: web based project topic in java
Views: 2044 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






