•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,931 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,272 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1220 | Replies: 6
![]() |
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation:
Rep Power: 0
Solved Threads: 31
what do you mean by select/dropdown ?
ajax is client side technology, any server side language will work well.
here is an example
ajax is client side technology, any server side language will work well.
here is an example
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
~Mitch Ratcliffe
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Rep Power: 1
Solved Threads: 1
In the below 3 programs
In getcustomer.jsp iam getting details from database according to the selected item in listbox in customer.html
now i want to put those result values in second listbox in customer.html
how is it possible tell me
if possible provide related code to the below example
customer.html
selectcustomer.js
getcustomer.jsp
In getcustomer.jsp iam getting details from database according to the selected item in listbox in customer.html
now i want to put those result values in second listbox in customer.html
how is it possible tell me
if possible provide related code to the below example
customer.html
<html> <head> <script src="selectcustomer.js"></script> </head><body><form> Select a Customer: <select name="customers" onchange="showCustomer(this.value)"> <option value="BS101">BS101 <option value="BS102">BS102 <option value="BS103">BS103 </select> <select> <option>--select--</select> </select> </form><p> <div id="txtHint"><b>Customer info will be listed here.</b></div> </p></body> </html>
var xmlHttp
function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="getcustomer.jsp";
url=url+"?q="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert(document.getElementById("txtHint").innerHTML=xmlHttp.responseText);
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}getcustomer.jsp
<%
Connection con;
con=dcon.getCon();
String q=request.getParameter("q");
System.out.println("q");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from PHR_FIN_MST_BS where BS_CODE='"+q+"'");
%>
<table>
<%
System.out.println("hi1");
while(rs.next()){
System.out.println("hi2");
%>
<tr><td><b><%
System.out.println("hi3"+rs.getString(1));
%></b></td></tr>
<tr><td><b><%=(rs.getString(2))%></b></td></tr>
<tr><td><b><%=(rs.getString(3))%></b></td></tr>
<tr><td><b><%=(rs.getString(4))%></b></td></tr>
<tr><td><b><%=(rs.getString(5))%></b></td></tr>
<tr><td><b><%=(rs.getString(6))%></b></td></tr>
<tr><td><b><%=(rs.getString(7))%></b></td></tr>
<tr><td><b><%=(rs.getString(8))%></b></td></tr>
<%
}//while
st.close();
rs.close();
con.close();
%>
</table>
</body>
</html> Last edited by MattEvans : Feb 26th, 2008 at 2:07 pm. Reason: Use [code] tags around blocks of code.
•
•
Join Date: Feb 2008
Location: bangalore
Posts: 19
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
•
•
In the below 3 programs
In getcustomer.jsp iam getting details from database according to the selected item in listbox in customer.html
now i want to put those result values in second listbox in customer.html
how is it possible tell me
if possible provide related code to the below example
customer.html
<html>
<head>
<script src="selectcustomer.js"></script>
</head><body><form>
Select a Customer:
<select name="customers" onchange="showCustomer(this.value)">
<option value="BS101">BS101
<option value="BS102">BS102
<option value="BS103">BS103
</select>
<select>
<option>--select--</select>
</select>
</form><p>
<div id="txtHint"><b>Customer info will be listed here.</b></div>
</p></body>
</html>
selectcustomer.js
var xmlHttp
function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="getcustomer.jsp";
url=url+"?q="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert(document.getElementById("txtHint").innerHTML=xmlHttp.responseText);
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
getcustomer.jsp
<%
Connection con;
con=dcon.getCon();
String q=request.getParameter("q");
System.out.println("q");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from PHR_FIN_MST_BS where BS_CODE='"+q+"'");
%>
<table>
<%
System.out.println("hi1");
while(rs.next()){
System.out.println("hi2");
%>
<tr><td><b><%
System.out.println("hi3"+rs.getString(1));
%></b></td></tr>
<tr><td><b><%=(rs.getString(2))%></b></td></tr>
<tr><td><b><%=(rs.getString(3))%></b></td></tr>
<tr><td><b><%=(rs.getString(4))%></b></td></tr>
<tr><td><b><%=(rs.getString(5))%></b></td></tr>
<tr><td><b><%=(rs.getString(6))%></b></td></tr>
<tr><td><b><%=(rs.getString(7))%></b></td></tr>
<tr><td><b><%=(rs.getString(8))%></b></td></tr>
<%
}//while
st.close();
rs.close();
con.close();
%>
</table>
</body>
</html>
this may help you
<html>
<head>
<script src="selectcustomer.js"></script>
<script language="javascript">
function moveOver()
{
var boxLength = document.choiceForm.SubCat.length;
var selectedItem = document.choiceForm.customers.selectedIndex;
var selectedText = document.choiceForm.customers.options[selectedItem].text;
var selectedValue = document.choiceForm.customers.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.SubCat.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.SubCat.options[boxLength] = newoption;
}
document.choiceForm.customers.selectedIndex=-1;
}
</script>
</head><body><form name="choiceForm">
Select a Customer:
<select name="customers" onchange="moveOver()">
<option value="BS101">BS101
<option value="BS102">BS102
<option value="BS103">BS103
</select>
<select id="SubCat" name="SubCat"></select>
</form>
</body></html> Last edited by MattEvans : Feb 26th, 2008 at 1:56 pm. Reason: Use [code] tags around blocks of code.
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation:
Rep Power: 0
Solved Threads: 31
hi
here i will give one example:
suppose you are getting three value from database- val1, val2, val3
you want to make a list box out of this then you need to return a list box from server side.
now form a string like this:
you should write System.ont.println() only once.
-idea is that whatever you will return from server, you will get from
you can do same for table also.
i hope this will help you.
Have a nice time !
here i will give one example:
suppose you are getting three value from database- val1, val2, val3
you want to make a list box out of this then you need to return a list box from server side.
now form a string like this:
string retStr; retStr="<select name='list_name' onchange='function_name(this.value)'> <option value=' "+val1+" '>"+val1+" <option value=' "+val1+" '>"+val1+" <option value=' "+val1+" '>"+val1+" </select>" System.out.println(retStr);
you should write System.ont.println() only once.
-idea is that whatever you will return from server, you will get from
xmlHttp.responseText at client side in ajax.you can do same for table also.
i hope this will help you.
Have a nice time !
Last edited by DangerDev : Feb 26th, 2008 at 9:03 am.
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
~Mitch Ratcliffe
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Previous Thread: javascript problem
- Next Thread: Ie Display (mozilla Is Ok)


Linear Mode