User Name Password Register
DaniWeb IT Discussion Community
All
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 375,195 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 2,156 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: 1233 | Replies: 6
Reply
Join Date: Feb 2008
Posts: 26
Reputation: brr is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
brr brr is offline Offline
Light Poster

select/dropdown in ajax

  #1  
Feb 25th, 2008
plz help me how to do select/dropdown
iam new to ajax
i followed the example select/dropdown from sourceforge net
but its not possible how to do it using jsp

plzzzzzzzzzzzz
help me in this, send me the code how to do it in jsp
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 31
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: can any one help

  #2  
Feb 25th, 2008
what do you mean by select/dropdown ?
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
Reply With Quote  
Join Date: Feb 2008
Posts: 26
Reputation: brr is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
brr brr is offline Offline
Light Poster

Troubleshooting To the second listbox

  #3  
Feb 26th, 2008
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>
Last edited by MattEvans : Feb 26th, 2008 at 2:07 pm. Reason: Use [code] tags around blocks of code.
Reply With Quote  
Join Date: Feb 2008
Location: bangalore
Posts: 19
Reputation: aravelli is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
aravelli aravelli is offline Offline
Newbie Poster

Re: To the second listbox

  #4  
Feb 26th, 2008
Originally Posted by brr View Post
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>
change this into customer.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.
Reply With Quote  
Join Date: Feb 2008
Posts: 26
Reputation: brr is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
brr brr is offline Offline
Light Poster

Re: To the second listbox

  #5  
Feb 26th, 2008
hai thanks for u help
but
iam asking abt what ever result items iam getting getcustomer.jsp by selecting one of item(BS101,BS102,BS103) IN customer.html THOSE ITEMS I HAVE TO PUT IN SECOND SELECT BOX
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 327
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 31
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: can any one help

  #6  
Feb 26th, 2008
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:
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
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 916
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 5
Solved Threads: 46
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: select/dropdown in ajax

  #7  
Feb 26th, 2008
This thread has been merged and re-named. The original merge sources were 'can anyone help' and 'To the second listbox'. Replies are now in chronological order as posted in both original threads.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC