Passing Parameter
Hi, it'me again. Below is the set of code that I get from your solution entitled droplist that read from database. It do read from database but in the textbox of the webpage, i need it to show something associated with the data i selected. Therefore, i've modify it into something like below which is from the selectbox.jsp. Notice that in the javascript part, there's var answer. I need to pass this parameter back into the jsp part, how should i do it which means the String answer in jsp part will equal to the var answer javascript part?
<%@ page language="java" import="java.util.*"%>
<%@ page import="java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*,java.lang.String
"%>
<html>
<head>
<script type="text/javascript">
function change()
{
var answer = document.getElementById('selc').value;
<%
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection connection=null;
ResultSet rs;
response.setContentType("text/html");
String price = "0";
String answer = "amir";
try {
// Load the database driver
Class.forName("com.mysql.jdbc.Driver");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL, "root", "123");
//Select the data from the database
String sql = "select * from message where message = '"+answer+"'";
Statement s = connection.createStatement();
s.executeQuery (sql);
rs = s.getResultSet();
while (rs.next ()){
price = rs.getString("price");
}
rs.close ();
s.close ();
}
catch(Exception e)
{
System.out.println("Exception is ;"+e);
}
%>
document.getElementById('textvalue').value= <%= price %>;
}
</script>
</head>
<body>
<h1>Use of Select Box in JSP</h1>
<table border="1" width="41%" height="53" cellspacing="0" cellpadding="3"
bgcolor="#000080" bordercolorlight="#FFFFFF">
<tr>
<td width="100%" height="18" colspan="2"><b>
<font color="#FF00FF">Select items from select box</font></b></td>
</tr>
<tr>
<td width="17%" height="23">
<select name="ActionSelect" onChange="change()" id="selc" >
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); )
{
String value=(String)itr.next();
%>
<option value=<%=value%>><%=value%></option>
<%}%>
</select>
</td>
<td width="83%" height="23"><input type="text" id="textvalue" />
</td>
</tr>
</table>
</body>
</html>
View Answers
April 17, 2010 at 12:24 PM
Hi Friend,
We have modified your code.Check it.
<%@ page language="java" import="java.util.*"%>
<%@ page import="java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*,java.lang.String
"%>
<html>
<head>
<script type="text/javascript">
function change(){
var answer = document.getElementById('selc').value;
window.location.replace("mod1.jsp?name="+answer);
}
</script>
<%
String ans=request.getParameter("name");
String connectionURL = "jdbc:
mysql://localhost:3306/register";;
Connection connection=null;
ResultSet rs;
response.setContentType("text/html");
String price = "";
String name = "";
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "root");
String sql = "select * from item where name = '"+ans+"'";
Statement s = connection.createStatement();
s.executeQuery (sql);
rs = s.getResultSet();
while (rs.next ()){
price = rs.getString("price");
name=rs.getString("name");
}
rs.close ();
s.close ();
}
catch(Exception e){
System.out.println("Exception is ;"+e);
}
System.out.println(price);
%>
</head>
<body>
<h1>Use of Select Box in JSP</h1>
<table border="1" width="41%" height="53" cellspacing="0" cellpadding="3"
bgcolor="#000080" bordercolorlight="#FFFFFF">
<tr>
<td width="100%" height="18" colspan="2"><b>
<font color="#FF00FF">Select items from select box</font></b></td>
</tr>
<tr>
<td width="17%" height="23">
<select name="ActionSelect" onChange="change()" id="selc" >
<%
String[] arr={"A","B","C","D","E"};
for(int i=0;i<arr.length;i++){
%>
<option value="<%=arr[i]%>"><%=arr[i]%></option>
<%
if(name.equals(arr[i])){
%>
<option value="<%=arr[i]%>" selected=selected><%=arr[i]%></option>
<%
}
}%>
</select>
</td>
<td width="83%" height="23"><input type="text" id="textvalue" value="<%= price %>" />
</td>
</tr>
</table>
</body>
</html>
Thanks
April 17, 2010 at 12:52 PM
We have performed action on same jsp page.Above jsp page has been saved as mod1.jsp.
thanks
Related Tutorials/Questions & Answers:
Passing Parameter - JSP-ServletPassing Parameter I would like to ask how to pass a
parameter from javascript section into the jsp section.It will be something like...;
answer<%; <---I'm stuck here
passing the var
Advertisements
Passing Parameter - JSP-ServletPassing Parameter Hi, it'me again. Below is the set of code that I get from your solution entitled droplist that read from database. It do read from..., there's var answer. I need to pass this
parameter back into the jsp part, how should i do
passing parameter from html to appletpassing parameter from html to applet how to pass the following from HTML to applet in Java code - font size,font style,font size?give me suitable code
Applet - Passing Parameter in Java Applet
Applet -
Passing Parameter in Java Applet
... and
passing parameter in applet, a
example is given below.
In this example, we... as
parameter. In our case applet should display "Welcome
in
Passing parameter JSP parameter passing throught out web appJSP
parameter passing throught out web app i want to pass one param from page1.jsp page to page4.jsp page but in between this i need to navigate page3.jsp and page2.jsp.Please help me to understand how could i transfer param
passing file parameter through ajax - Ajaxpassing file
parameter through ajax I have file
parameter in jsp file, i need to pass it to server side through ajax. how i can i do that. Hi friend,
file1.jsp
passing file using jsp
JSP:Passing query as parameter - Java BeginnersJSP:
Passing query as parameter Hi Friends,
I have a real tough...";
String qry3="select age from table13";
string
q=Insert into emp values(?,?,?);
int update=prep.executeUpdate(
q);
prep.setString(1,qry1);
prep.setString
JSP:Passing query as parameter - Java BeginnersJSP:
Passing query as parameter Hi Friends,
I have a real tough...";
String qry3="select age from table13";
string
q=Insert into emp values(?,?,?);
int update=prep.executeUpdate(
q);
prep.setString(1,qry1);
prep.setString
Passing variablePassing variable How to pass variable to HTTP object in HTMl or PHP
Passing Parameter with <jsp: include>Passing Parameter with <jsp: include>
In this example we are going to use <jsp:include> action tag.
This action tag has one attribute page which is used to include
Argument PassingPassing Argument in Java hi this is my code
class Test {
void meth(int i, int j) {
i *= 2;
j /= 2... to the
parameter
of the subroutine have no effect on the argument
plz clear my
Argument Passing);
print a=30 & b=10
As changes made to the
parameter
of the subroutine have
Argument Passing);
print a=30 & b=10
As changes made to the
parameter
of the subroutine have
Argument Passing);
print a=30 & b=10
As changes made to the
parameter
of the subroutine have
Argument Passing);
print a=30 & b=10
As changes made to the
parameter
of the subroutine have
Argument Passing);
print a=30 & b=10
As changes made to the
parameter
of the subroutine have
Argument Passing);
print a=30 & b=10
As changes made to the
parameter
of the subroutine have
Passing Parameters - JSP-ServletPassing Parameters Hi
I have to pass
parameter like such scenario. Please help me on emergent bases. I will be grateful.
First Page
First Name
/**SECOND PAGER upto this page I passed the
parameter through query
Passing Parameter Using Html Form Passing Parameter Using Html Form
This is a very simple example in which we are going to
display the name on the browser which we have entered from the Html page
Passing array elementPassing array element What about
passing an element of an array? If I have array of objects and pass functionA(arr[2]); Then functionA() will get arr[2] as a value type or a reference type
ModuleNotFoundError: No module named 'parameter'ModuleNotFoundError: No module named '
parameter' Hi,
My Python... '
parameter'
How to remove the ModuleNotFoundError: No module named '
parameter' error?
Thanks
Hi,
In your python environment you
Objective C Message PassingObjective C Message Passing What exactly a message
passing means in Objective C? and how can i pass a message to a method
Passing classid or name in request using JqueryPassing classid or name in request using Jquery Hi, I am new... filename,userid that I am
passing to the servlet to upload a file.I have created... with
parameter so that I save my file with that name.
Can some body help me as I am
passing values on button clickpassing values on button click Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
Reference passing in javaReference
passing in java plz tell me wat d meaning of refernce in java?
for example :
Class M(){
N n;
}
Class N(){
}
wats dis meaning
passing values in hyperlinkpassing values in hyperlink Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlinkpassing values in hyperlink Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlinkpassing values in hyperlink Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlinkpassing values in hyperlink Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlinkpassing values in hyperlink Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
Passing Arguments. - Java BeginnersPassing Arguments. Hi, im new in doing this
passing arguments and calling methods. Can you please see that y im not getting the answer as the question says to do.
Thanks
Question:Write a method that is passed two arguments
passing value of radio buttonpassing value of radio button hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after
passing through the second
pass parameter names and valuespass
parameter names and values What is the <jsp:param> standard action?
The <jsp:param> standard action is used with <jsp:include> or <jsp:forward> to pass
parameter names and values
JSP Session Parameter rewrite
JSP Session
Parameter rewrite
In the section you will study about the session
parameter...;
<title>JSP Session
Parameter Rewrite</title>
</head>
<
optional parameter of Test annotattion optional
parameter of Test annotattion What are two optional parameters of @Test annotation ?
The Test annotation supports two optional...
parameter, timeout, causes a test to fail if it takes longer than a specified amount
SQL Out Parameter
SQL Out
Parameter
SQL Out
Parameter allows the stored procedure to the pass data value ... illustrate an example from SQL Out
Parameter .In this Example we
create a procedure
optional parameter of Test annotattion optional
parameter of Test annotattion The Test annotation supports two optional parameters. The first, expected, declares that a test method should throw an exception. If it doesn't throw an exception or if it throws