JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 5th, 2012, 09:30 PM
messimagic messimagic is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 5 messimagic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 20 m 57 sec
Reputation Power: 0
Post Sending array of values using ajax

I am sending multiselect dropdown values to a JSP PAGE. Below is the AJAX code that send the multiselect values. The JSP PAge includes SQL query to read from database and show its values in another dropdown. Below code only display cascading dropdown values based on select and not multiselect. It appears that only one value is sent to apps.jsp and not all values. I tried few changes and it didn't work. Below is the best working code available with me. Any help to get second dropdown display values based on multiselect from first dropdown? Single dropdown works fine with below code. Thank you.

PHP Code:
<select multiple="multiple" name="RequirementFor" id="RequirementFor" onchange="showState(this.value);">

 <
option value="1">Test1</option>
    <
option value="2">Test2</option>
<
option value="3">Test3</option>
<
option value="4">Test4</option>
</
select>
<
div id="plat"><select name="Platform" id="Platform"  multiple="multiple"     onchange='showState2(this.value)'>

    </
select></div>
//AJAX Code
var xmlHttp 
var 
xmlHttp;
function 
showState(str){

if (
typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (
window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (
xmlHttp==null){
alert("Browser does not support XMLHTTP Request");
return;

var 
url="apps.jsp";
url +="?value=" +str;
xmlHttp.onreadystatechange stateChange;
xmlHttp.open("GET"urltrue);
xmlHttp.send(null);
}

function 
stateChange(){   
if (
xmlHttp.readyState==|| xmlHttp.readyState=="complete"){   
document.getElementById("plat").innerHTML=xmlHttp.responseText   ;
}


Reply With Quote
  #2  
Old November 6th, 2012, 02:46 AM
hdewantara's Avatar
hdewantara hdewantara is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Location: Jakarta, Indonesia.
Posts: 149 hdewantara User rank is Sergeant Major (2000 - 5000 Reputation Level)hdewantara User rank is Sergeant Major (2000 - 5000 Reputation Level)hdewantara User rank is Sergeant Major (2000 - 5000 Reputation Level)hdewantara User rank is Sergeant Major (2000 - 5000 Reputation Level)hdewantara User rank is Sergeant Major (2000 - 5000 Reputation Level)hdewantara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 18 h 50 m 40 sec
Reputation Power: 30
Send a message via MSN to hdewantara
I don't know how your JSP handles the query, but maybe it could use something from this example:
Code:
<script>
function showState(me){
	var values = ''; //populate selected options
	for (var i=0; i<me.options.length; i++)
		if (me.options[i].selected) values += me.options[i].value + ',';
	document.getElementById('report').value = values; //report
}
</script>

<select multiple="multiple" onchange="showState(this);">
	<option value="1">Test1</option>
	<option value="2">Test2</option>
	<option value="3">Test3</option>
	<option value="4">Test4</option>
</select> 

<input type="text" id="report">
Comments on this post
Winters agrees: Teaches me for leaving the thread open for an hour without refreshing.
messimagic agrees!

Reply With Quote
  #3  
Old November 6th, 2012, 04:03 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,874 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 17 h 24 m 7 sec
Reputation Power: 2569
Already answered.
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Last edited by Winters : November 6th, 2012 at 04:06 AM. Reason: Already answered.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Sending array of values using ajax

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap